]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/lockmgr.h
Add pool memory debug output
[bacula/bacula] / bacula / src / lib / lockmgr.h
index cd94decb36fff88d9916f0e1039a2f7486bbbecf..17dd2a9985d657d686dc2cedba87de348249d059 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2008-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2008-2010 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation, which is 
    listed in the file LICENSE.
 
    License as published by the Free Software Foundation, which is 
    listed in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -29,6 +29,8 @@
 #ifndef _LOCKMGR_H
 #define _LOCKMGR_H 1
 
 #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)
 /*
  * P and V op that don't use the lock manager (for memory allocation or on
  * win32)
@@ -84,6 +86,12 @@ int bthread_mutex_lock_p(bthread_mutex_t *m,
 int bthread_mutex_unlock_p(bthread_mutex_t *m, 
                            const char *file="*unknown*", int line=0);
 
 int bthread_mutex_unlock_p(bthread_mutex_t *m, 
                            const char *file="*unknown*", int line=0);
 
+/*  Test if this mutex is locked by the current thread
+ *     0 - not locked by the current thread
+ *     1 - locked by the current thread
+ */
+int lmgr_mutex_is_locked(void *m);
+                   
 /* 
  * Use them when you want use your lock yourself (ie rwlock)
  */
 /* 
  * Use them when you want use your lock yourself (ie rwlock)
  */
@@ -151,20 +159,30 @@ int lmgr_thread_create(pthread_t *thread,
                        void *(*start_routine)(void*), void *arg);
 
 /* 
                        void *(*start_routine)(void*), void *arg);
 
 /* 
- * Define _LOCKMGR_COMPLIANT to use real pthread functions
+ * Can use SAFEKILL to check if the argument is a valid threadid
  */
  */
+int bthread_kill(pthread_t thread, int sig, 
+                 const char *file="*unknown*", int line=0);
+
+#define BTHREAD_MUTEX_NO_PRIORITY      {PTHREAD_MUTEX_INITIALIZER, 0}
+#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
+#endif
 
 
-#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 bthread_mutex_lock(x)      bthread_mutex_lock_p(x, __FILE__, __LINE__)
 #define bthread_mutex_lock(x)      bthread_mutex_lock_p(x, __FILE__, __LINE__)
-#define bthread_mutex_unlock(x)    bthread_mutex_unlock_p
+#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 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))
 #ifdef _LOCKMGR_COMPLIANT
 # define P(x) lmgr_p(&(x))
 # define V(x) lmgr_v(&(x))
@@ -176,6 +194,10 @@ 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_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)
+
+# ifdef USE_LOCKMGR_SAFEKILL
+#  define pthread_kill(a,b)      bthread_kill((a),(b), __FILE__, __LINE__)
+# endif
 #endif
 
 #else   /* _USE_LOCKMGR */
 #endif
 
 #else   /* _USE_LOCKMGR */
@@ -184,25 +206,26 @@ int lmgr_thread_create(pthread_t *thread,
 # define lmgr_dump()
 # define lmgr_init_thread()
 # define lmgr_cleanup_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_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 lmgr_do_unlock(m)
 # define lmgr_cleanup_main()
-# define bthread_mutex_set_priority(a)
-# define bthread_mutex_lock(a)       pthread_mutex_lock(a)
-# define bthread_mutex_unlock(a)     pthread_mutex_unlock(a)
-# define lmgr_cond_wait(a,b)         pthread_cond_wait(a,b)
-# define lmgr_cond_timedwait(a,b,c)  pthread_cond_timedwait(a,b,c)
-# define bthread_mutex_t             pthread_mutex_t
+# define bthread_mutex_set_priority(a,b)
+# define bthread_mutex_lock(a)           pthread_mutex_lock(a)
+# define bthread_mutex_lock_p(a, f, l)   pthread_mutex_lock(a)
+# define bthread_mutex_unlock(a)         pthread_mutex_unlock(a)
+# define bthread_mutex_unlock_p(a, f, l) pthread_mutex_unlock(a)
+# define lmgr_cond_wait(a,b)             pthread_cond_wait(a,b)
+# define lmgr_cond_timedwait(a,b,c)      pthread_cond_timedwait(a,b,c)
+# define bthread_mutex_t                 pthread_mutex_t
 # define P(x) lmgr_p(&(x))
 # define V(x) lmgr_v(&(x))
 # define P(x) lmgr_p(&(x))
 # define V(x) lmgr_v(&(x))
-# 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
+# define BTHREAD_MUTEX_PRIORITY(p)      PTHREAD_MUTEX_INITIALIZER
+# define BTHREAD_MUTEX_NO_PRIORITY      PTHREAD_MUTEX_INITIALIZER
+# define BTHREAD_MUTEX_INITIALIZER      PTHREAD_MUTEX_INITIALIZER
+# define lmgr_mutex_is_locked(m)        (1)
+
 #endif  /* _USE_LOCKMGR */
 
 #endif  /* _LOCKMGR_H */
 #endif  /* _USE_LOCKMGR */
 
 #endif  /* _LOCKMGR_H */