]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/lockmgr.h
Tweak mutex order for SD
[bacula/bacula] / bacula / src / lib / lockmgr.h
index afce8bd180e2b4a3e3930913cb81f02baa62700f..03210a9880001b8e242988efa362fa4e53d44ac8 100644 (file)
@@ -29,6 +29,8 @@
 #ifndef _LOCKMGR_H
 #define _LOCKMGR_H 1
 
+#include "mutex_list.h"     /* Manage mutex with priority in a central place */
+
 /*
  * P and V op that don't use the lock manager (for memory allocation or on
  * win32)
@@ -150,22 +152,26 @@ int lmgr_thread_create(pthread_t *thread,
                        const pthread_attr_t *attr,
                        void *(*start_routine)(void*), void *arg);
 
-/* 
- * Define _LOCKMGR_COMPLIANT to use real pthread functions
- */
-
-#define BTHREAD_MUTEX_PRIORITY(p)      {PTHREAD_MUTEX_INITIALIZER, p}
 #define BTHREAD_MUTEX_NO_PRIORITY      {PTHREAD_MUTEX_INITIALIZER, 0}
-#define BTHREAD_MUTEX_PRIORITY_1       {PTHREAD_MUTEX_INITIALIZER, 1}
-#define BTHREAD_MUTEX_PRIORITY_2       {PTHREAD_MUTEX_INITIALIZER, 2}
-#define BTHREAD_MUTEX_PRIORITY_3       {PTHREAD_MUTEX_INITIALIZER, 3}
-#define BTHREAD_MUTEX_PRIORITY_4       {PTHREAD_MUTEX_INITIALIZER, 4}
 #define BTHREAD_MUTEX_INITIALIZER      BTHREAD_MUTEX_NO_PRIORITY
+
+/* Define USE_LOCKMGR_PRIORITY to detect mutex wrong order */
+#ifdef USE_LOCKMGR_PRIORITY
+# define BTHREAD_MUTEX_PRIORITY(p)       {PTHREAD_MUTEX_INITIALIZER, p}
+#else
+# define BTHREAD_MUTEX_PRIORITY(p)       BTHREAD_MUTEX_NO_PRIORITY
+# define bthread_mutex_set_priority(x,y)
+#endif
+
 #define bthread_mutex_lock(x)      bthread_mutex_lock_p(x, __FILE__, __LINE__)
 #define bthread_mutex_unlock(x)    bthread_mutex_unlock_p(x, __FILE__, __LINE__)
 #define bthread_cond_wait(x,y)     bthread_cond_wait_p(x,y, __FILE__, __LINE__)
 #define bthread_cond_timedwait(x,y,z) bthread_cond_timedwait_p(x,y,z, __FILE__, __LINE__)
 
+/* 
+ * Define _LOCKMGR_COMPLIANT to use real pthread functions
+ */
+
 #ifdef _LOCKMGR_COMPLIANT
 # define P(x) lmgr_p(&(x))
 # define V(x) lmgr_v(&(x))
@@ -185,9 +191,9 @@ int lmgr_thread_create(pthread_t *thread,
 # define lmgr_dump()
 # define lmgr_init_thread()
 # define lmgr_cleanup_thread()
-# define lmgr_pre_lock(m, f, l)
+# define lmgr_pre_lock(m, prio, f, l)
 # define lmgr_post_lock()
-# define lmgr_do_lock(m, f, l)
+# define lmgr_do_lock(m, prio, f, l)
 # define lmgr_do_unlock(m)
 # define lmgr_cleanup_main()
 # define bthread_mutex_set_priority(a)
@@ -200,13 +206,7 @@ int lmgr_thread_create(pthread_t *thread,
 # define V(x) lmgr_v(&(x))
 # define BTHREAD_MUTEX_PRIORITY(p)      PTHREAD_MUTEX_INITIALIZER
 # define BTHREAD_MUTEX_NO_PRIORITY      PTHREAD_MUTEX_INITIALIZER
-# define BTHREAD_MUTEX_PRIORITY_1       PTHREAD_MUTEX_INITIALIZER
-# define BTHREAD_MUTEX_PRIORITY_2       PTHREAD_MUTEX_INITIALIZER
-# define BTHREAD_MUTEX_PRIORITY_3       PTHREAD_MUTEX_INITIALIZER
-# define BTHREAD_MUTEX_PRIORITY_4       PTHREAD_MUTEX_INITIALIZER
 # define BTHREAD_MUTEX_INITIALIZER      PTHREAD_MUTEX_INITIALIZER
 #endif  /* _USE_LOCKMGR */
 
-#include "mutex_list.h"     /* Manage mutex with priority in a central place */
-
 #endif  /* _LOCKMGR_H */