04ef78d78a8910c5fc3ffd8e1f643edb685f0951
[platform/upstream/multipath-tools.git] / libmultipath / lock.h
1 #ifndef _LOCK_H
2 #define _LOCK_H
3
4 #include <signal.h>
5
6 /*
7  * Wrapper for the mutex. Includes a ref-count to keep
8  * track of how many there are out-standing threads blocking
9  * on a mutex. */
10 struct mutex_lock {
11         pthread_mutex_t *mutex;
12         int depth;
13 };
14
15 #ifdef LCKDBG
16 #define lock(a) \
17                 fprintf(stderr, "%s:%s(%i) lock %p depth: %d (%ld)\n", __FILE__, __FUNCTION__, __LINE__, a.mutex, a.depth, pthread_self()); \
18                 a.depth++; pthread_mutex_lock(a.mutex)
19 #define unlock(a) \
20                 fprintf(stderr, "%s:%s(%i) unlock %p depth: %d (%ld)\n", __FILE__, __FUNCTION__, __LINE__, a.mutex, a.depth, pthread_self()); \
21         a.depth--; pthread_mutex_unlock(a.mutex)
22 #define lock_cleanup_pop(a) \
23                 fprintf(stderr, "%s:%s(%i) unlock %p depth: %d (%ld)\n", __FILE__, __FUNCTION__, __LINE__, a.mutex, a.depth, pthread_self()); \
24         pthread_cleanup_pop(1);
25 #else
26 #define lock(a) a.depth++; pthread_mutex_lock(a.mutex)
27 #define unlock(a) a.depth--; pthread_mutex_unlock(a.mutex)
28 #define lock_cleanup_pop(a) pthread_cleanup_pop(1);
29 #endif
30
31 void cleanup_lock (void * data);
32
33 #endif /* _LOCK_H */