Go to the documentation of this file.
27 #ifndef SURICATA_THREADS_DEBUG_H
28 #define SURICATA_THREADS_DEBUG_H
37 #define SCMutexLock_dbg(mut) ({ \
38 printf("%16s(%s:%d): (thread:%"PRIuMAX") locking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
39 int retl = pthread_mutex_lock(mut); \
40 printf("%16s(%s:%d): (thread:%"PRIuMAX") locked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retl); \
44 printf("The value specified by attr is invalid\n"); \
45 retl = pthread_mutex_init(mut, NULL); \
48 retl = pthread_mutex_lock(mut); \
51 printf("A deadlock would occur if the thread blocked waiting for mutex\n"); \
58 #define SCMutexTrylock_dbg(mut) ({ \
59 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
60 int rett = pthread_mutex_trylock(mut); \
61 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, rett); \
65 printf("%16s(%s:%d): The value specified by attr is invalid\n", __FUNCTION__, __FILE__, __LINE__); \
68 printf("Mutex is already locked\n"); \
75 #define SCMutexInit_dbg(mut, mutattr) ({ \
77 ret = pthread_mutex_init(mut, mutattr); \
81 printf("The value specified by attr is invalid\n"); \
82 printf("%16s(%s:%d): (thread:%"PRIuMAX") mutex %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, ret); \
85 printf("The system temporarily lacks the resources to create another mutex\n"); \
86 printf("%16s(%s:%d): (thread:%"PRIuMAX") mutex %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, ret); \
89 printf("The process cannot allocate enough memory to create another mutex\n"); \
90 printf("%16s(%s:%d): (thread:%"PRIuMAX") mutex %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, ret); \
97 #define SCMutexUnlock_dbg(mut) ({ \
98 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
99 int retu = pthread_mutex_unlock(mut); \
100 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \
104 printf("%16s(%s:%d): The value specified by attr is invalid\n", __FUNCTION__, __FILE__, __LINE__); \
107 printf("The current thread does not hold a lock on mutex\n"); \
114 #define SCMutex pthread_mutex_t
115 #define SCMutexAttr pthread_mutexattr_t
116 #define SCMutexInit(mut, mutattrs) SCMutexInit_dbg(mut, mutattrs)
117 #define SCMutexLock(mut) SCMutexLock_dbg(mut)
118 #define SCMutexTrylock(mut) SCMutexTrylock_dbg(mut)
119 #define SCMutexIsLocked(mut) (SCMutexTrylock(mut) == EBUSY)
120 #define SCMutexUnlock(mut) SCMutexUnlock_dbg(mut)
121 #define SCMutexDestroy pthread_mutex_destroy
122 #define SCMUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
126 #define SCCondWait_dbg(cond, mut) ({ \
127 int ret = pthread_cond_wait(cond, mut); \
130 printf("The value specified by attr is invalid (or a SCCondT not initialized!)\n"); \
131 printf("%16s(%s:%d): (thread:%"PRIuMAX") failed SCCondWait %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, ret); \
138 #define SCCondT pthread_cond_t
139 #define SCCondInit pthread_cond_init
140 #define SCCondSignal pthread_cond_signal
141 #define SCCondDestroy pthread_cond_destroy
142 #define SCCondWait SCCondWait_dbg
146 #define SCSpinLock_dbg(spin) ({ \
147 printf("%16s(%s:%d): (thread:%"PRIuMAX") locking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
148 int ret = pthread_spin_lock(spin); \
149 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
152 printf("The value specified by attr is invalid\n"); \
155 printf("A deadlock would occur if the thread blocked waiting for spin\n"); \
161 #define SCSpinTrylock_dbg(spin) ({ \
162 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
163 int ret = pthread_spin_trylock(spin); \
164 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
167 printf("The value specified by attr is invalid\n"); \
170 printf("A deadlock would occur if the thread blocked waiting for spin\n"); \
173 printf("A thread currently holds the lock\n"); \
179 #define SCSpinUnlock_dbg(spin) ({ \
180 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
181 int ret = pthread_spin_unlock(spin); \
182 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlockedspin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
185 printf("The value specified by attr is invalid\n"); \
188 printf("The calling thread does not hold the lock\n"); \
194 #define SCSpinInit_dbg(spin, spin_attr) ({ \
195 int ret = pthread_spin_init(spin, spin_attr); \
196 printf("%16s(%s:%d): (thread:%"PRIuMAX") spinlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
199 printf("The value specified by attr is invalid\n"); \
202 printf("A thread currently holds the lock\n"); \
205 printf("The process cannot allocate enough memory to create another spin\n"); \
208 printf("The system temporarily lacks the resources to create another spin\n"); \
214 #define SCSpinDestroy_dbg(spin) ({ \
215 printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p waiting\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
216 int ret = pthread_spin_destroy(spin); \
217 printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p passed %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
220 printf("The value specified by attr is invalid\n"); \
223 printf("A thread currently holds the lock\n"); \
226 printf("The process cannot allocate enough memory to create another spin\n"); \
229 printf("The system temporarily lacks the resources to create another spin\n"); \
235 #define SCSpinlock pthread_spinlock_t
236 #define SCSpinLock SCSpinLock_dbg
237 #define SCSpinTrylock SCSpinTrylock_dbg
238 #define SCSpinUnlock SCSpinUnlock_dbg
239 #define SCSpinInit SCSpinInit_dbg
240 #define SCSpinDestroy SCSpinDestroy_dbg
248 #define SCRWLockRDLock_dbg(rwl) ({ \
249 printf("%16s(%s:%d): (thread:%"PRIuMAX") locking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
250 int retl = pthread_rwlock_rdlock(rwl); \
251 printf("%16s(%s:%d): (thread:%"PRIuMAX") locked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, retl); \
255 printf("The value specified by attr is invalid\n"); \
256 retl = pthread_rwlock_init(rwl, NULL); \
258 exit(EXIT_FAILURE); \
259 retl = pthread_rwlock_rdlock(rwl); \
262 printf("A deadlock would occur if the thread blocked waiting for rwlock\n"); \
269 #define SCRWLockWRLock_dbg(rwl) ({ \
270 printf("%16s(%s:%d): (thread:%"PRIuMAX") locking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
271 int retl = pthread_rwlock_wrlock(rwl); \
272 printf("%16s(%s:%d): (thread:%"PRIuMAX") locked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, retl); \
276 printf("The value specified by attr is invalid\n"); \
277 retl = pthread_rwlock_init(rwl, NULL); \
279 exit(EXIT_FAILURE); \
280 retl = pthread_rwlock_wrlock(rwl); \
283 printf("A deadlock would occur if the thread blocked waiting for rwlock\n"); \
291 #define SCRWLockTryWRLock_dbg(rwl) ({ \
292 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
293 int rett = pthread_rwlock_trywrlock(rwl); \
294 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, rett); \
298 printf("%16s(%s:%d): The value specified by attr is invalid\n", __FUNCTION__, __FILE__, __LINE__); \
301 printf("RWLock is already locked\n"); \
308 #define SCRWLockTryRDLock_dbg(rwl) ({ \
309 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
310 int rett = pthread_rwlock_tryrdlock(rwl); \
311 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, rett); \
315 printf("%16s(%s:%d): The value specified by attr is invalid\n", __FUNCTION__, __FILE__, __LINE__); \
318 printf("RWLock is already locked\n"); \
325 #define SCRWLockInit_dbg(rwl, rwlattr) ({ \
327 ret = pthread_rwlock_init(rwl, rwlattr); \
331 printf("The value specified by attr is invalid\n"); \
332 printf("%16s(%s:%d): (thread:%"PRIuMAX") rwlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, ret); \
335 printf("The system temporarily lacks the resources to create another rwlock\n"); \
336 printf("%16s(%s:%d): (thread:%"PRIuMAX") rwlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, ret); \
339 printf("The process cannot allocate enough memory to create another rwlock\n"); \
340 printf("%16s(%s:%d): (thread:%"PRIuMAX") rwlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, ret); \
347 #define SCRWLockUnlock_dbg(rwl) ({ \
348 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
349 int retu = pthread_rwlock_unlock(rwl); \
350 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, retu); \
354 printf("%16s(%s:%d): The value specified by attr is invalid\n", __FUNCTION__, __FILE__, __LINE__); \
357 printf("The current thread does not hold a lock on rwlock\n"); \
364 #define SCRWLock pthread_rwlock_t
365 #define SCRWLockInit(rwl, rwlattrs) SCRWLockInit_dbg(rwl, rwlattrs)
366 #define SCRWLockRDLock(rwl) SCRWLockRDLock_dbg(rwl)
367 #define SCRWLockWRLock(rwl) SCRWLockWRLock_dbg(rwl)
368 #define SCRWLockTryWRLock(rwl) SCRWLockTryWRLock_dbg(rwl)
369 #define SCRWLockTryRDLock(rwl) SCRWLockTryRDLock_dbg(rwl)
370 #define SCRWLockUnlock(rwl) SCRWLockUnlock_dbg(rwl)
371 #define SCRWLockDestroy pthread_rwlock_destroy
374 #define SCCtrlMutex pthread_mutex_t
375 #define SCCtrlMutexAttr pthread_mutexattr_t
376 #define SCCtrlMutexInit(mut, mutattr ) pthread_mutex_init(mut, mutattr)
377 #define SCCtrlMutexLock(mut) pthread_mutex_lock(mut)
378 #define SCCtrlMutexTrylock(mut) pthread_mutex_trylock(mut)
379 #define SCCtrlMutexUnlock(mut) pthread_mutex_unlock(mut)
380 #define SCCtrlMutexDestroy pthread_mutex_destroy
383 #define SCCtrlCondT pthread_cond_t
384 #define SCCtrlCondInit pthread_cond_init
385 #define SCCtrlCondSignal pthread_cond_signal
386 #define SCCtrlCondTimedwait pthread_cond_timedwait
387 #define SCCtrlCondWait pthread_cond_wait
388 #define SCCtrlCondDestroy pthread_cond_destroy