Fork me on GitHub
mutex.h
Go to the documentation of this file.
1 
10 #ifndef _JANUS_MUTEX_H
11 #define _JANUS_MUTEX_H
12 
13 #include <pthread.h>
14 #include <errno.h>
15 
16 #include "debug.h"
17 
18 extern int lock_debug;
19 
20 #ifdef USE_PTHREAD_MUTEX
21 
23 typedef pthread_mutex_t janus_mutex;
25 #define janus_mutex_init(a) pthread_mutex_init(a,NULL)
26 
27 #define JANUS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
28 
29 #define janus_mutex_destroy(a) pthread_mutex_destroy(a)
30 
31 #define janus_mutex_lock_nodebug(a) pthread_mutex_lock(a);
32 
33 #define janus_mutex_lock_debug(a) { JANUS_PRINT("[%s:%s:%d:lock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); pthread_mutex_lock(a); };
34 
35 #define janus_mutex_lock(a) { if(!lock_debug) { janus_mutex_lock_nodebug(a); } else { janus_mutex_lock_debug(a); } };
36 
37 #define janus_mutex_unlock_nodebug(a) pthread_mutex_unlock(a);
38 
39 #define janus_mutex_unlock_debug(a) { JANUS_PRINT("[%s:%s:%d:unlock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); pthread_mutex_unlock(a); };
40 
41 #define janus_mutex_unlock(a) { if(!lock_debug) { janus_mutex_unlock_nodebug(a); } else { janus_mutex_unlock_debug(a); } };
42 
44 typedef pthread_cond_t janus_condition;
46 #define janus_condition_init(a) pthread_cond_init(a,NULL)
47 
48 #define janus_condition_destroy(a) pthread_cond_destroy(a)
49 
50 #define janus_condition_wait(a, b) pthread_cond_wait(a, b);
51 
52 #define janus_condition_timedwait(a, b, c) pthread_cond_timedwait(a, b, c);
53 
54 #define janus_condition_signal(a) pthread_cond_signal(a);
55 
56 #define janus_condition_broadcast(a) pthread_cond_broadcast(a);
57 
58 #else
59 
61 typedef GMutex janus_mutex;
63 #define janus_mutex_init(a) g_mutex_init(a)
64 
65 #define JANUS_MUTEX_INITIALIZER {0}
66 
67 #define janus_mutex_destroy(a) g_mutex_clear(a)
68 
69 #define janus_mutex_lock_nodebug(a) g_mutex_lock(a);
70 
71 #define janus_mutex_lock_debug(a) { JANUS_PRINT("[%s:%s:%d:lock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); g_mutex_lock(a); };
72 
73 #define janus_mutex_lock(a) { if(!lock_debug) { janus_mutex_lock_nodebug(a); } else { janus_mutex_lock_debug(a); } };
74 
75 #define janus_mutex_unlock_nodebug(a) g_mutex_unlock(a);
76 
77 #define janus_mutex_unlock_debug(a) { JANUS_PRINT("[%s:%s:%d:unlock] %p\n", __FILE__, __FUNCTION__, __LINE__, a); g_mutex_unlock(a); };
78 
79 #define janus_mutex_unlock(a) { if(!lock_debug) { janus_mutex_unlock_nodebug(a); } else { janus_mutex_unlock_debug(a); } };
80 
82 typedef GCond janus_condition;
84 #define janus_condition_init(a) g_cond_init(a)
85 
86 #define janus_condition_destroy(a) g_cond_clear(a)
87 
88 #define janus_condition_wait(a, b) g_cond_wait(a, b);
89 
90 #define janus_condition_wait_until(a, b, c) g_cond_wait_until(a, b, c);
91 
92 #define janus_condition_signal(a) g_cond_signal(a);
93 
94 #define janus_condition_broadcast(a) g_cond_broadcast(a);
95 
96 #endif
97 
98 #endif
Logging and Debugging.
GMutex janus_mutex
Janus mutex implementation.
Definition: mutex.h:61
int lock_debug
Definition: janus.c:334
GCond janus_condition
Janus condition implementation.
Definition: mutex.h:82