summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/transport_master.h
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2018-09-24 17:34:25 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2018-09-27 11:31:13 -0400
commitb6aefaf100cfaaf15297a8921cca51a575c5e78e (patch)
treef32a6c045e7b9b74e0b4db0b61add8e3b0a7cc3c /libs/ardour/ardour/transport_master.h
parent3c11660d2a3ec31a559f4b940a622ed735dbb054 (diff)
initial hacks towards a truly thread-safe SafeTime object, using boost::atomic
Diffstat (limited to 'libs/ardour/ardour/transport_master.h')
-rw-r--r--libs/ardour/ardour/transport_master.h34
1 files changed, 30 insertions, 4 deletions
diff --git a/libs/ardour/ardour/transport_master.h b/libs/ardour/ardour/transport_master.h
index b41d107015..da30abfae9 100644
--- a/libs/ardour/ardour/transport_master.h
+++ b/libs/ardour/ardour/transport_master.h
@@ -23,6 +23,7 @@
#include <vector>
#include <boost/optional.hpp>
+#include <boost/atomic.hpp>
#include <glibmm/threads.h>
@@ -282,18 +283,43 @@ class LIBARDOUR_API TransportMaster : public PBD::Stateful {
};
struct LIBARDOUR_API SafeTime {
- volatile int guard1;
+ boost::atomic<int> guard1;
samplepos_t position;
samplepos_t timestamp;
double speed;
- volatile int guard2;
+ boost::atomic<int> guard2;
SafeTime() {
- guard1 = 0;
+ guard1.store (0);
position = 0;
timestamp = 0;
speed = 0;
- guard2 = 0;
+ guard2.store (0);
+ }
+
+ SafeTime (SafeTime const & other)
+ : guard1 (other.guard1.load (boost::memory_order_acquire))
+ , position (other.position)
+ , timestamp (other.timestamp)
+ , speed (other.speed)
+ , guard2 (other.guard2.load (boost::memory_order_acquire))
+ {}
+
+ SafeTime& operator= (SafeTime const & other) {
+ guard1 = other.guard1.load (boost::memory_order_acquire);
+ position = other.position;
+ timestamp = other.timestamp;
+ speed = other.speed;
+ guard2 = other.guard2.load (boost::memory_order_acquire);
+ return *this;
+ }
+
+ void update (samplepos_t p, samplepos_t t, double s) {
+ guard1.fetch_add (1, boost::memory_order_acquire);
+ position = p;
+ timestamp = t;
+ speed = s;
+ guard2.fetch_add (1, boost::memory_order_acquire);
}
};