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 SCMutexUnlock(mut) SCMutexUnlock_dbg(mut)
120 #define SCMutexDestroy pthread_mutex_destroy
121 #define SCMUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
125 #define SCCondWait_dbg(cond, mut) ({ \
126 int ret = pthread_cond_wait(cond, mut); \
129 printf("The value specified by attr is invalid (or a SCCondT not initialized!)\n"); \
130 printf("%16s(%s:%d): (thread:%"PRIuMAX") failed SCCondWait %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, ret); \
137 #define SCCondT pthread_cond_t
138 #define SCCondInit pthread_cond_init
139 #define SCCondSignal pthread_cond_signal
140 #define SCCondDestroy pthread_cond_destroy
141 #define SCCondWait SCCondWait_dbg
145 #define SCSpinLock_dbg(spin) ({ \
146 printf("%16s(%s:%d): (thread:%"PRIuMAX") locking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
147 int ret = pthread_spin_lock(spin); \
148 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
151 printf("The value specified by attr is invalid\n"); \
154 printf("A deadlock would occur if the thread blocked waiting for spin\n"); \
160 #define SCSpinTrylock_dbg(spin) ({ \
161 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
162 int ret = pthread_spin_trylock(spin); \
163 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
166 printf("The value specified by attr is invalid\n"); \
169 printf("A deadlock would occur if the thread blocked waiting for spin\n"); \
172 printf("A thread currently holds the lock\n"); \
178 #define SCSpinUnlock_dbg(spin) ({ \
179 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
180 int ret = pthread_spin_unlock(spin); \
181 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlockedspin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
184 printf("The value specified by attr is invalid\n"); \
187 printf("The calling thread does not hold the lock\n"); \
193 #define SCSpinInit_dbg(spin, spin_attr) ({ \
194 int ret = pthread_spin_init(spin, spin_attr); \
195 printf("%16s(%s:%d): (thread:%"PRIuMAX") spinlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
198 printf("The value specified by attr is invalid\n"); \
201 printf("A thread currently holds the lock\n"); \
204 printf("The process cannot allocate enough memory to create another spin\n"); \
207 printf("The system temporarily lacks the resources to create another spin\n"); \
213 #define SCSpinDestroy_dbg(spin) ({ \
214 printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p waiting\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
215 int ret = pthread_spin_destroy(spin); \
216 printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p passed %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
219 printf("The value specified by attr is invalid\n"); \
222 printf("A thread currently holds the lock\n"); \
225 printf("The process cannot allocate enough memory to create another spin\n"); \
228 printf("The system temporarily lacks the resources to create another spin\n"); \
234 #define SCSpinlock pthread_spinlock_t
235 #define SCSpinLock SCSpinLock_dbg
236 #define SCSpinTrylock SCSpinTrylock_dbg
237 #define SCSpinUnlock SCSpinUnlock_dbg
238 #define SCSpinInit SCSpinInit_dbg
239 #define SCSpinDestroy SCSpinDestroy_dbg
247 #define SCRWLockRDLock_dbg(rwl) ({ \
248 printf("%16s(%s:%d): (thread:%"PRIuMAX") locking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
249 int retl = pthread_rwlock_rdlock(rwl); \
250 printf("%16s(%s:%d): (thread:%"PRIuMAX") locked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, retl); \
254 printf("The value specified by attr is invalid\n"); \
255 retl = pthread_rwlock_init(rwl, NULL); \
257 exit(EXIT_FAILURE); \
258 retl = pthread_rwlock_rdlock(rwl); \
261 printf("A deadlock would occur if the thread blocked waiting for rwlock\n"); \
268 #define SCRWLockWRLock_dbg(rwl) ({ \
269 printf("%16s(%s:%d): (thread:%"PRIuMAX") locking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
270 int retl = pthread_rwlock_wrlock(rwl); \
271 printf("%16s(%s:%d): (thread:%"PRIuMAX") locked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, retl); \
275 printf("The value specified by attr is invalid\n"); \
276 retl = pthread_rwlock_init(rwl, NULL); \
278 exit(EXIT_FAILURE); \
279 retl = pthread_rwlock_wrlock(rwl); \
282 printf("A deadlock would occur if the thread blocked waiting for rwlock\n"); \
290 #define SCRWLockTryWRLock_dbg(rwl) ({ \
291 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
292 int rett = pthread_rwlock_trywrlock(rwl); \
293 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, rett); \
297 printf("%16s(%s:%d): The value specified by attr is invalid\n", __FUNCTION__, __FILE__, __LINE__); \
300 printf("RWLock is already locked\n"); \
307 #define SCRWLockTryRDLock_dbg(rwl) ({ \
308 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
309 int rett = pthread_rwlock_tryrdlock(rwl); \
310 printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, rett); \
314 printf("%16s(%s:%d): The value specified by attr is invalid\n", __FUNCTION__, __FILE__, __LINE__); \
317 printf("RWLock is already locked\n"); \
324 #define SCRWLockInit_dbg(rwl, rwlattr) ({ \
326 ret = pthread_rwlock_init(rwl, rwlattr); \
330 printf("The value specified by attr is invalid\n"); \
331 printf("%16s(%s:%d): (thread:%"PRIuMAX") rwlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, ret); \
334 printf("The system temporarily lacks the resources to create another rwlock\n"); \
335 printf("%16s(%s:%d): (thread:%"PRIuMAX") rwlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, ret); \
338 printf("The process cannot allocate enough memory to create another rwlock\n"); \
339 printf("%16s(%s:%d): (thread:%"PRIuMAX") rwlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, ret); \
346 #define SCRWLockUnlock_dbg(rwl) ({ \
347 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking rwlock %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl); \
348 int retu = pthread_rwlock_unlock(rwl); \
349 printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked rwlock %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), rwl, retu); \
353 printf("%16s(%s:%d): The value specified by attr is invalid\n", __FUNCTION__, __FILE__, __LINE__); \
356 printf("The current thread does not hold a lock on rwlock\n"); \
363 #define SCRWLock pthread_rwlock_t
364 #define SCRWLockInit(rwl, rwlattrs) SCRWLockInit_dbg(rwl, rwlattrs)
365 #define SCRWLockRDLock(rwl) SCRWLockRDLock_dbg(rwl)
366 #define SCRWLockWRLock(rwl) SCRWLockWRLock_dbg(rwl)
367 #define SCRWLockTryWRLock(rwl) SCRWLockTryWRLock_dbg(rwl)
368 #define SCRWLockTryRDLock(rwl) SCRWLockTryRDLock_dbg(rwl)
369 #define SCRWLockUnlock(rwl) SCRWLockUnlock_dbg(rwl)
370 #define SCRWLockDestroy pthread_rwlock_destroy
373 #define SCCtrlMutex pthread_mutex_t
374 #define SCCtrlMutexAttr pthread_mutexattr_t
375 #define SCCtrlMutexInit(mut, mutattr ) pthread_mutex_init(mut, mutattr)
376 #define SCCtrlMutexLock(mut) pthread_mutex_lock(mut)
377 #define SCCtrlMutexTrylock(mut) pthread_mutex_trylock(mut)
378 #define SCCtrlMutexUnlock(mut) pthread_mutex_unlock(mut)
379 #define SCCtrlMutexDestroy pthread_mutex_destroy
382 #define SCCtrlCondT pthread_cond_t
383 #define SCCtrlCondInit pthread_cond_init
384 #define SCCtrlCondSignal pthread_cond_signal
385 #define SCCtrlCondTimedwait pthread_cond_timedwait
386 #define SCCtrlCondWait pthread_cond_wait
387 #define SCCtrlCondDestroy pthread_cond_destroy