]> Dogcows Code - chaz/yoink/blobdiff - src/moof/thread.hh
prep for runloop code
[chaz/yoink] / src / moof / thread.hh
index 09caefd3048800a0cab77380bbceb62743700e96..72c6dc004147461706c1ae8d405b3c25fc924d62 100644 (file)
@@ -9,13 +9,15 @@
 *
 **************************************************************************/
 
+#ifndef _MOOF_THREAD_HH_
+#define _MOOF_THREAD_HH_
+
 /**
  * \file thread.hh
  * Light C++ wrapper around the SDL threads API.
  */
 
-#ifndef _MOOF_THREAD_HH_
-#define _MOOF_THREAD_HH_
+#include "config.h"
 
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
@@ -252,9 +254,12 @@ public:
                 * Construct a lock.
                 * \param mutex The mutex.
                 */
-        explicit lock(mutex& mutex) :
+        explicit lock(mutex& mutex, bool lock = true) :
                        mutex_(mutex),
-                       is_locked_(false) {}
+                       is_locked_(false)
+               {
+                       if (lock) if (!acquire()) throw "mutex lock not acquired";
+               }
 
                /**
                 * Deconstruct a lock.  The lock is automagically released if it is
@@ -305,34 +310,6 @@ public:
         friend class condition;
     };
 
-       /**
-        * This type of lock tries to acquire a lock on the mutex during
-        * construction and releases the lock on deconstruction.
-        */
-    class scoped_lock : private lock
-    {
-       public:
-
-               /**
-                * Construct a lock.
-                * \param mutex The mutex.
-                */
-               explicit scoped_lock(mutex& mutex) :
-                       lock(mutex)
-               {
-                       acquire();
-               }
-
-               /**
-                * Get whether or not the mutex is locked.
-                * \return True if the mutex is locked, false otherwise.
-                */
-               bool is_locked() const
-               {
-                       return lock::is_locked();
-               }
-    };
-
 
 private:
 
@@ -531,9 +508,12 @@ public:
                 * Construct a lock.
                 * \param semaphore The semaphore.
                 */
-        explicit lock(semaphore& semaphore) :
+        explicit lock(semaphore& semaphore, bool lock = true) :
                        semaphore_(semaphore),
-                       is_locked_(false) {}
+                       is_locked_(false)
+               {
+                       if (lock) if (!acquire()) throw "semaphore lock not acquired";
+               }
 
                /**
                 * Deconstruct a lock.  The lock is automagically released if it is
@@ -580,34 +560,6 @@ public:
         semaphore&     semaphore_;
         bool           is_locked_;
     };
-    
-       /**
-        * This type of lock tries to acquire a lock on the semaphore during
-        * construction and releases the lock on deconstruction.
-        */
-    class scoped_lock : private lock
-    {
-    public:
-
-               /**
-                * Construct a lock.
-                * \param semaphore The semaphore.
-                */
-        explicit scoped_lock(semaphore& semaphore) :
-                       lock(semaphore)
-               {
-                       acquire();
-               }
-
-               /**
-                * Get whether or not the semaphore is locked.
-                * \return True if the semaphore is locked, false otherwise.
-                */
-               bool is_locked() const
-               {
-                       return lock::is_locked();
-               }
-    };
 
 
 private:
@@ -616,6 +568,15 @@ private:
 };
 
 
+#if ENABLE_THREADS
+#define MOOF_DECLARE_MUTEX(M)  moof::mutex M
+#define MOOF_MUTEX_LOCK(M)             moof::mutex::lock lock_##M(M)
+#else
+#define MOOF_DECLARE_MUTEX(M)
+#define MOOF_MUTEX_LOCK(M)
+#endif
+
+
 } // namespace moof
 
 #endif // _MOOF_THREAD_HH_
This page took 0.022886 seconds and 4 git commands to generate.