more objectification for SafeTime
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 25 Sep 2018 15:53:52 +0000 (11:53 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 27 Sep 2018 15:31:13 +0000 (11:31 -0400)
libs/ardour/ardour/transport_master.h
libs/ardour/mtc_slave.cc

index da30abfae9445a65f8d872d1c079ff6f2cd00ee0..81d250dda9825690e84be00d397d5ffaa07c456a 100644 (file)
 #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
index 7a6d6a6ed6f481e0d931ec0ed8526cb93eb45266..d110c2a32dec94a939dc9779d62ebbd147a920cc 100644 (file)
@@ -32,8 +32,6 @@
 #include "ardour/session.h"
 #include "ardour/transport_master.h"
 
-#include <glibmm/timer.h>
-
 #include "pbd/i18n.h"
 
 using namespace std;
@@ -259,23 +257,6 @@ MTC_TransportMaster::handle_locate (const MIDI::byte* mmc_tc)
        update_mtc_time (mtc, true, 0);
 }
 
-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)
 {
@@ -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';