summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2018-09-25 11:53:52 -0400
committerPaul Davis <paul@linuxaudiosystems.com>2018-09-27 11:31:13 -0400
commit0f7123d33a1ab879191046b86d382318f35fd570 (patch)
tree19b007a5d15846d18deb205a88aea2983edc7b93
parentb6aefaf100cfaaf15297a8921cca51a575c5e78e (diff)
more objectification for SafeTime
-rw-r--r--libs/ardour/ardour/transport_master.h30
-rw-r--r--libs/ardour/mtc_slave.cc25
2 files changed, 24 insertions, 31 deletions
diff --git a/libs/ardour/ardour/transport_master.h b/libs/ardour/ardour/transport_master.h
index da30abfae9..81d250dda9 100644
--- a/libs/ardour/ardour/transport_master.h
+++ b/libs/ardour/ardour/transport_master.h
@@ -26,9 +26,11 @@
#include <boost/atomic.hpp>
#include <glibmm/threads.h>
+#include <glibmm/timer.h>
#include <ltc.h>
+#include "pbd/i18n.h"
#include "pbd/properties.h"
#include "pbd/signals.h"
#include "pbd/stateful.h"
@@ -305,15 +307,6 @@ struct LIBARDOUR_API SafeTime {
, 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;
@@ -321,6 +314,25 @@ struct LIBARDOUR_API SafeTime {
speed = s;
guard2.fetch_add (1, boost::memory_order_acquire);
}
+
+ void safe_read (SafeTime& dst) const {
+ int tries = 0;
+
+ do {
+ if (tries == 10) {
+ std::cerr << X_("SafeTime: atomic read of current time failed, sleeping!") << std::endl;
+ Glib::usleep (20);
+ tries = 0;
+ }
+ dst.guard1.store (guard1.load (boost::memory_order_seq_cst), boost::memory_order_seq_cst);
+ dst.position = position;
+ dst.timestamp = timestamp;
+ dst.speed = speed;
+ dst.guard2.store (guard2.load (boost::memory_order_seq_cst), boost::memory_order_seq_cst);
+ tries++;
+
+ } while (dst.guard1.load (boost::memory_order_seq_cst) != dst.guard2.load (boost::memory_order_seq_cst));
+ }
};
/** a helper class for any TransportMaster that receives its input via a MIDI
diff --git a/libs/ardour/mtc_slave.cc b/libs/ardour/mtc_slave.cc
index 7a6d6a6ed6..d110c2a32d 100644
--- a/libs/ardour/mtc_slave.cc
+++ b/libs/ardour/mtc_slave.cc
@@ -32,8 +32,6 @@
#include "ardour/session.h"
#include "ardour/transport_master.h"
-#include <glibmm/timer.h>
-
#include "pbd/i18n.h"
using namespace std;
@@ -260,23 +258,6 @@ MTC_TransportMaster::handle_locate (const MIDI::byte* mmc_tc)
}
void
-MTC_TransportMaster::read_current (SafeTime *st) const
-{
- int tries = 0;
-
- do {
- if (tries == 10) {
- error << _("MTC Slave: atomic read of current time failed, sleeping!") << endmsg;
- Glib::usleep (20);
- tries = 0;
- }
- *st = current;
- tries++;
-
- } while (st->guard1.load (boost::memory_order_acquire) != st->guard2.load (boost::memory_order_acquire));
-}
-
-void
MTC_TransportMaster::init_mtc_dll(samplepos_t tme, double qtr)
{
const double omega = 2.0 * M_PI * qtr / 2.0 / double(_session->sample_rate());
@@ -579,7 +560,7 @@ MTC_TransportMaster::speed_and_position (double& speed, samplepos_t& pos, sample
return false;
}
- read_current (&last);
+ current.safe_read (last);
DEBUG_TRACE (DEBUG::MTC, string_compose ("speed&pos: timestamp %1 speed %2 dir %4 now %5 last-in %6\n",
last.timestamp,
@@ -634,7 +615,7 @@ std::string
MTC_TransportMaster::position_string() const
{
SafeTime last;
- read_current (&last);
+ current.safe_read (last);
if (last.timestamp == 0 || reset_pending) {
return " --:--:--:--";
}
@@ -650,7 +631,7 @@ MTC_TransportMaster::delta_string () const
{
char delta[80];
SafeTime last;
- read_current (&last);
+ current.safe_read (last);
delta[0] = '\0';