#include <vector>
#include <boost/optional.hpp>
+#include <boost/atomic.hpp>
#include <glibmm/threads.h>
};
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);
}
};
*st = current;
tries++;
- } while (st->guard1 != st->guard2);
+ } while (st->guard1.load (boost::memory_order_acquire) != st->guard2.load (boost::memory_order_acquire));
}
void
mtc_speed = (t1 - t0) / qtr_d;
DEBUG_TRACE (DEBUG::MTC, string_compose ("qtr sample DLL t0:%1 t1:%2 err:%3 spd:%4 ddt:%5\n", t0, t1, e, mtc_speed, e2 - qtr_d));
- current.guard1++;
- current.position = mtc_frame;
- current.timestamp = now;
- current.speed = mtc_speed;
- current.guard2++;
+ current.update (mtc_frame, now, mtc_speed);
last_inbound_frame = now;
}
init_mtc_dll(mtc_frame, qtr);
mtc_frame_dll = mtc_frame;
}
- current.guard1++;
- current.position = mtc_frame;
- current.timestamp = now;
- current.guard2++;
+ current.update (mtc_frame, now, current.speed);
reset_window (mtc_frame);
}
}
switch (status) {
case MTC_Stopped:
- current.guard1++;
- current.position = mtc_frame;
- current.timestamp = 0;
- current.speed = 0;
- current.guard2++;
-
+ current.update (mtc_frame, 0, 0);
break;
case MTC_Forward:
- current.guard1++;
- current.position = mtc_frame;
- current.timestamp = 0;
- current.speed = 0;
- current.guard2++;
+ current.update (mtc_frame, 0, 0);
break;
case MTC_Backward:
- current.guard1++;
- current.position = mtc_frame;
- current.timestamp = 0;
- current.speed = 0;
- current.guard2++;
+ current.update (mtc_frame, 0, 0);
break;
}
busy_guard2++;