From d6fcaa11a39f46bdbf3c17f74805aa1106f1cb4e Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 8 Dec 2009 21:19:54 +0100 Subject: [PATCH] Add init/destroy function for both p/bthread_mutex_t object --- bacula/src/lib/lockmgr.c | 44 ++++++++++++++++++++++++++++++++++++++++ bacula/src/lib/lockmgr.h | 6 ++++++ 2 files changed, 50 insertions(+) diff --git a/bacula/src/lib/lockmgr.c b/bacula/src/lib/lockmgr.c index d882da271e..24f6aa2c58 100644 --- a/bacula/src/lib/lockmgr.c +++ b/bacula/src/lib/lockmgr.c @@ -26,6 +26,33 @@ 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 diff --git a/bacula/src/lib/lockmgr.h b/bacula/src/lib/lockmgr.h index fdde9c7a2a..c7a9afeec0 100644 --- a/bacula/src/lib/lockmgr.h +++ b/bacula/src/lib/lockmgr.h @@ -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 */ -- 2.39.5