2 Bacula® - The Network Backup Solution
4 Copyright (C) 2008-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation, which is
11 listed in the file LICENSE.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
35 * P and V op that don't use the lock manager (for memory allocation or on
38 void lmgr_p(pthread_mutex_t *m);
39 void lmgr_v(pthread_mutex_t *m);
44 * We decide that a thread won't lock more than LMGR_MAX_LOCK at the same time
46 #define LMGR_MAX_LOCK 32
49 int lmgr_cond_wait(pthread_cond_t *cond,
50 pthread_mutex_t *mutex,
51 const char *file="*unknown*", int line=0);
53 /* Replacement of pthread_mutex_lock() */
54 int lmgr_mutex_lock(pthread_mutex_t *m,
55 const char *file="*unknown*", int line=0);
57 /* Replacement of pthread_mutex_unlock() */
58 int lmgr_mutex_unlock(pthread_mutex_t *m,
59 const char *file="*unknown*", int line=0);
62 * Use them when you want use your lock yourself (ie rwlock)
65 /* Call before requesting the lock */
66 void lmgr_pre_lock(void *m, const char *file="*unknown*", int line=0);
68 /* Call after getting it */
69 void lmgr_post_lock();
71 /* Same as pre+post lock */
72 void lmgr_do_lock(void *m, const char *file="*unknown*", int line=0);
74 /* Call just before releasing the lock */
75 void lmgr_do_unlock(void *m);
78 * Each thread have to call this function to put a lmgr_thread_t object
79 * in the stack and be able to call mutex_lock/unlock
81 void lmgr_init_thread();
84 * Call this function at the end of the thread
86 void lmgr_cleanup_thread();
89 * Call this at the end of the program, it will release the
92 void lmgr_cleanup_main();
95 * Dump each lmgr_thread_t object to stdout
102 bool lmgr_detect_deadlock();
105 * Search a deadlock after a fatal signal
106 * no lock are granted, so the program must be
109 bool lmgr_detect_deadlock_unlocked();
112 * This function will run your thread with lmgr_init_thread() and
113 * lmgr_cleanup_thread().
115 int lmgr_thread_create(pthread_t *thread,
116 const pthread_attr_t *attr,
117 void *(*start_routine)(void*), void *arg);
120 * Define _LOCKMGR_COMPLIANT to use real pthread functions
123 #ifdef _LOCKMGR_COMPLIANT
124 # define P(x) lmgr_p(&(x))
125 # define V(x) lmgr_v(&(x))
127 # define P(x) lmgr_mutex_lock(&(x), __FILE__, __LINE__)
128 # define V(x) lmgr_mutex_unlock(&(x), __FILE__, __LINE__)
129 # define pthread_mutex_lock(x) lmgr_mutex_lock(x, __FILE__, __LINE__)
130 # define pthread_mutex_unlock(x) lmgr_mutex_unlock(x, __FILE__, __LINE__)
131 # define pthread_cond_wait(x,y) lmgr_cond_wait(x,y, __FILE__, __LINE__)
132 # define pthread_create(a, b, c, d) lmgr_thread_create(a,b,c,d)
135 #else /* _USE_LOCKMGR */
137 # define lmgr_detect_deadloc()
139 # define lmgr_init_thread()
140 # define lmgr_cleanup_thread()
141 # define lmgr_pre_lock(m, f, l)
142 # define lmgr_post_lock()
143 # define lmgr_do_lock(m, f, l)
144 # define lmgr_do_unlock(m)
145 # define lmgr_cleanup_main()
146 # define P(x) lmgr_p(&(x))
147 # define V(x) lmgr_v(&(x))
149 #endif /* _USE_LOCKMGR */
151 #endif /* _LOCKMGR_H */