Another try at fixing our 'spinlock_t' compatibility
authorJohn Emmas <johne53@tiscali.co.uk>
Mon, 29 Jul 2019 15:56:45 +0000 (16:56 +0100)
committerJohn Emmas <johne53@tiscali.co.uk>
Mon, 29 Jul 2019 15:56:45 +0000 (16:56 +0100)
libs/pbd/pbd/spinlock.h
libs/pbd/spinlock.cc

index 2e543408dfe4b4e6030312bc00829caafd786c48..d8706c68c962a78a63fbbdba67aebf3b52f5b0d4 100644 (file)
@@ -20,6 +20,8 @@
 #define _pbd_spinlock_h_
 
 #include <boost/smart_ptr/detail/spinlock.hpp>
+#include <cstring>
+
 #include "pbd/libpbd_visibility.h"
 
 namespace PBD {
@@ -35,10 +37,23 @@ namespace PBD {
 
 struct spinlock_t {
 public:
-       spinlock_t ();
+#ifdef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
+       /* C++11 non-static data member initialization,
+        * with non-copyable std::atomic ATOMIC_FLAG_INIT
+        */
+       spinlock_t () : l (BOOST_DETAIL_SPINLOCK_INIT) {};
+#else
+       /* default C++ assign struct's first member */
+       spinlock_t ()
+       {
+               boost::detail::spinlock init = BOOST_DETAIL_SPINLOCK_INIT;
+               std::memcpy (&l, &init, sizeof (init));
+       }
+#endif
        void lock () { l.lock (); }
        void unlock () { l.unlock (); }
        bool try_lock () { return l.try_lock (); }
+
 private:
        boost::detail::spinlock l;
 
index ff6fe51b1bbfdce354c0bc84bae1fae579e0a55c..d42bc8db69c2c91aad541dc69beba7d7157a7699 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-#ifdef PLATFORM_WINDOWS
-#include <windows.h>
-#include <malloc.h>
-#endif
-
-#include <cstring>
-
 #include "pbd/spinlock.h"
 
 using namespace PBD;
 
-spinlock_t::spinlock_t ()
-#ifdef BOOST_SMART_PTR_DETAIL_SPINLOCK_STD_ATOMIC_HPP_INCLUDED
-       /* C++11 non-static data member initialization,
-        * with non-copyable std::atomic ATOMIC_FLAG_INIT
-        */
-       : l {BOOST_DETAIL_SPINLOCK_INIT} {}
-#else
-       /* default C++ assign struct's first member */
-{
-       boost::detail::spinlock init = BOOST_DETAIL_SPINLOCK_INIT;
-       std::memcpy (&l, &init, sizeof (init));
-}
-#endif
-
 SpinLock::SpinLock (spinlock_t& lock)
        : _lock (lock)
 {