]> git.sur5r.net Git - bacula/bacula/commitdiff
Add init/destroy function for both p/bthread_mutex_t object
authorEric Bollengier <eric@eb.homelinux.org>
Tue, 8 Dec 2009 20:19:54 +0000 (21:19 +0100)
committerEric Bollengier <eric@eb.homelinux.org>
Tue, 8 Dec 2009 20:19:54 +0000 (21:19 +0100)
bacula/src/lib/lockmgr.c
bacula/src/lib/lockmgr.h

index d882da271ef7fa1b3dbd54139bd49a93494a741e..24f6aa2c58910650491ae2b712b1bcac8aa6d3b3 100644 (file)
    Switzerland, email:ftf@fsfeurope.org.
 */
 
+/*
+  How to use mutex with bad order usage detection
+ ------------------------------------------------
+
+ Instead of using:
+    pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    P(mutex);
+    ..
+    V(mutex);
+
+ use:
+    bthread_mutex_t mutex = BTHREAD_MUTEX_PRIORITY_1;
+    P(mutex);
+    ...
+    V(mutex);
+
+ Mutex that doesn't need this extra check can be declared as pthread_mutex_t.
+ You can use this object on pthread_mutex_lock/unlock/cond_wait/cond_timewait.
+ With dynamic creation, you can use:
+    bthread_mutex_t mutex;
+    pthread_mutex_init(&mutex);     // you can also use bthread_mutex_init()
+    bthread_mutex_set_priority(&mutex, 10);
+    pthread_mutex_destroy(&mutex);
+ */
+
 #define _LOCKMGR_COMPLIANT
 #include "bacula.h"
 
@@ -675,6 +702,23 @@ int bthread_mutex_destroy(bthread_mutex_t *m)
    return pthread_mutex_destroy(&m->mutex);
 }
 
+/*
+ * Replacement for pthread_mutex_init() for pthread_mutex_t
+ */
+int bthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *attr)
+{
+   return pthread_mutex_init(m, attr);
+}
+
+/*
+ * Replacement for pthread_mutex_destroy() for pthread_mutex_t
+ */
+int bthread_mutex_destroy(pthread_mutex_t *m)
+{
+   return pthread_mutex_destroy(m);
+}
+
+
 /*
  * Replacement for pthread_mutex_lock()
  * Returns always ok 
index fdde9c7a2add07a9ec71de8843f39b7a86321d17..c7a9afeec052617b0853731ce81488dce1b997f9 100644 (file)
@@ -106,6 +106,10 @@ int bthread_mutex_init(bthread_mutex_t *m, const pthread_mutexattr_t *attr);
 int bthread_mutex_destroy(bthread_mutex_t *m);
 void bthread_mutex_set_priority(bthread_mutex_t *m, int prio);
 
+/* init/destroy for real pthread_mutex_t object */
+int bthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *attr);
+int bthread_mutex_destroy(pthread_mutex_t *m);
+
 /*
  * Each thread have to call this function to put a lmgr_thread_t object
  * in the stack and be able to call mutex_lock/unlock
@@ -174,6 +178,8 @@ int lmgr_thread_create(pthread_t *thread,
 # define pthread_mutex_unlock(x)         bthread_mutex_unlock(x)
 # define pthread_cond_wait(x,y)          bthread_cond_wait(x,y)
 # define pthread_cond_timedwait(x,y,z)   bthread_cond_timedwait(x,y,z)
+# define pthread_mutex_init(x,y)         bthread_mutex_init(x,y)
+# define pthread_mutex_destroy(x)        bthread_mutex_destroy(x)
 #endif
 
 #else   /* _USE_LOCKMGR */