elock.h: add possibility to create recursive mutexes
authorghost <andreas.monzner@multimedia-labs.de>
Thu, 17 Dec 2009 13:46:04 +0000 (14:46 +0100)
committerghost <andreas.monzner@multimedia-labs.de>
Thu, 17 Dec 2009 14:15:20 +0000 (15:15 +0100)
lib/base/elock.h

index 51582e67fe5a3d6e97ba97c82856c4bcd3127019..01757182a06a7dc4166421a91a6a5990e3844004 100644 (file)
@@ -83,9 +83,18 @@ class eSingleLock
        pthread_mutex_t m_lock;
        eSingleLock(eSingleLock &);
 public:
-       eSingleLock()
+       eSingleLock(bool recursive=false)
        {
-               pthread_mutex_init(&m_lock, 0);
+               if (recursive)
+               {
+                       pthread_mutexattr_t attr;
+                       pthread_mutexattr_init(&attr);
+                       pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+                       pthread_mutex_init(&m_lock, &attr);
+                       pthread_mutexattr_destroy(&attr);
+               }
+               else
+                       pthread_mutex_init(&m_lock, 0);
        }
        ~eSingleLock()
        {