|
|
|
@ -20,9 +20,9 @@
|
|
|
|
//#define DBG_THREADS
|
|
|
|
//#define DBG_THREADS
|
|
|
|
|
|
|
|
|
|
|
|
/** Suricata Mutex */
|
|
|
|
/** Suricata Mutex */
|
|
|
|
#define sc_mutex_t pthread_mutex_t
|
|
|
|
#define SCMutex pthread_mutex_t
|
|
|
|
#define sc_mutexattr_t pthread_mutexattr_t
|
|
|
|
#define SCMutexAttr pthread_mutexattr_t
|
|
|
|
#define sc_mutex_destroy pthread_mutex_destroy
|
|
|
|
#define SCMutexDestroy pthread_mutex_destroy
|
|
|
|
|
|
|
|
|
|
|
|
/** Mutex Functions */
|
|
|
|
/** Mutex Functions */
|
|
|
|
#ifdef DBG_THREADS
|
|
|
|
#ifdef DBG_THREADS
|
|
|
|
@ -31,7 +31,7 @@
|
|
|
|
* It is for Mac OS X users;
|
|
|
|
* It is for Mac OS X users;
|
|
|
|
* If you see a mutex, spinlock or condiion not initialized, report it please!
|
|
|
|
* If you see a mutex, spinlock or condiion not initialized, report it please!
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#define sc_mutex_lock_dbg(mut) ({ \
|
|
|
|
#define SCMutexLock_dbg(mut) ({ \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") locking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") locking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
|
|
|
|
int retl = pthread_mutex_lock(mut); \
|
|
|
|
int retl = pthread_mutex_lock(mut); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") locked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retl); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") locked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retl); \
|
|
|
|
@ -52,7 +52,7 @@
|
|
|
|
retl; \
|
|
|
|
retl; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_mutex_trylock_dbg(mut) ({ \
|
|
|
|
#define SCMutexTrylock_dbg(mut) ({ \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
|
|
|
|
int rett = pthread_mutex_trylock(mut); \
|
|
|
|
int rett = pthread_mutex_trylock(mut); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, rett); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, rett); \
|
|
|
|
@ -69,7 +69,7 @@
|
|
|
|
rett; \
|
|
|
|
rett; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_mutex_init_dbg(mut, mutattr) ({ \
|
|
|
|
#define SCMutexInit_dbg(mut, mutattr) ({ \
|
|
|
|
int ret; \
|
|
|
|
int ret; \
|
|
|
|
ret = pthread_mutex_init(mut, mutattr); \
|
|
|
|
ret = pthread_mutex_init(mut, mutattr); \
|
|
|
|
if (ret != 0) { \
|
|
|
|
if (ret != 0) { \
|
|
|
|
@ -91,7 +91,7 @@
|
|
|
|
ret; \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_mutex_unlock_dbg(mut) ({ \
|
|
|
|
#define SCMutexUnlock_dbg(mut) ({ \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking mutex %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut); \
|
|
|
|
int retu = pthread_mutex_unlock(mut); \
|
|
|
|
int retu = pthread_mutex_unlock(mut); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked mutex %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \
|
|
|
|
@ -108,55 +108,55 @@
|
|
|
|
retu; \
|
|
|
|
retu; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_mutex_init(mut, mutattrs) sc_mutex_init_dbg(mut, mutattrs)
|
|
|
|
#define SCMutexInit(mut, mutattrs) SCMutexInit_dbg(mut, mutattrs)
|
|
|
|
#define sc_mutex_lock(mut) sc_mutex_lock_dbg(mut)
|
|
|
|
#define SCMutexLock(mut) SCMutexLock_dbg(mut)
|
|
|
|
#define sc_mutex_trylock(mut) sc_mutex_trylock_dbg(mut)
|
|
|
|
#define SCMutexTrylock(mut) SCMutexTrylock_dbg(mut)
|
|
|
|
#define sc_mutex_unlock(mut) sc_mutex_unlock_dbg(mut)
|
|
|
|
#define SCMutexUnlock(mut) SCMutexUnlock_dbg(mut)
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#define sc_mutex_init(mut, mutattr ) pthread_mutex_init(mut, mutattr)
|
|
|
|
#define SCMutexInit(mut, mutattr ) pthread_mutex_init(mut, mutattr)
|
|
|
|
#define sc_mutex_lock(mut) pthread_mutex_lock(mut)
|
|
|
|
#define SCMutexLock(mut) pthread_mutex_lock(mut)
|
|
|
|
#define sc_mutex_trylock(mut) pthread_mutex_trylock(mut)
|
|
|
|
#define SCMutexTrylock(mut) pthread_mutex_trylock(mut)
|
|
|
|
#define sc_mutex_unlock(mut) pthread_mutex_unlock(mut)
|
|
|
|
#define SCMutexUnlock(mut) pthread_mutex_unlock(mut)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/** Conditions/Signals */
|
|
|
|
/** Conditions/Signals */
|
|
|
|
/* Here we don't need to do nothing atm */
|
|
|
|
/* Here we don't need to do nothing atm */
|
|
|
|
#define sc_cond_t pthread_cond_t
|
|
|
|
#define SCCondT pthread_cond_t
|
|
|
|
#define sc_cond_init pthread_cond_init
|
|
|
|
#define SCCondInit pthread_cond_init
|
|
|
|
#define sc_cond_signal pthread_cond_signal
|
|
|
|
#define SCCondSignal pthread_cond_signal
|
|
|
|
#define sc_cond_timedwait pthread_cond_timedwait
|
|
|
|
#define SCCondTimedwait pthread_cond_timedwait
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DBG_THREAD
|
|
|
|
#ifdef DBG_THREAD
|
|
|
|
#define sc_cond_wait_dbg(cond, mut) ({ \
|
|
|
|
#define SCondWait_dbg(cond, mut) ({ \
|
|
|
|
int ret = pthread_cond_wait(cond, mut); \
|
|
|
|
int ret = pthread_cond_wait(cond, mut); \
|
|
|
|
switch (ret) { \
|
|
|
|
switch (ret) { \
|
|
|
|
case EINVAL: \
|
|
|
|
case EINVAL: \
|
|
|
|
printf("The value specified by attr is invalid (or a sc_cond_t not initialized!)\n"); \
|
|
|
|
printf("The value specified by attr is invalid (or a SCCondT not initialized!)\n"); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") failed sc_cond_wait %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") failed SCondWait %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), mut, retu); \
|
|
|
|
break; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
ret; \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
#define sc_cond_wait sc_cond_wait_dbg
|
|
|
|
#define SCondWait SCondWait_dbg
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#define sc_cond_wait(cond, mut) pthread_cond_wait(cond, mut)
|
|
|
|
#define SCondWait(cond, mut) pthread_cond_wait(cond, mut)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/** Spinlocks */
|
|
|
|
/** Spinlocks */
|
|
|
|
#define sc_spin_t pthread_spinlock_t
|
|
|
|
#define SCSpinlock pthread_spinlock_t
|
|
|
|
|
|
|
|
|
|
|
|
/** If posix spin not supported, use mutex */
|
|
|
|
/** If posix spin not supported, use mutex */
|
|
|
|
#if ((_POSIX_SPIN_LOCKS - 200112L) < 0L)
|
|
|
|
#if ((_POSIX_SPIN_LOCKS - 200112L) < 0L)
|
|
|
|
#define pthread_spinlock_t pthread_mutex_t
|
|
|
|
#define pthread_spinlock_t pthread_mutex_t
|
|
|
|
#define pthread_spin_init(target,arg) sc_mutex_init(target, NULL)
|
|
|
|
#define pthread_spin_init(target,arg) SCMutexInit(target, NULL)
|
|
|
|
#define pthread_spin_lock(spin) sc_mutex_lock(spin)
|
|
|
|
#define pthread_spin_lock(spin) SCMutexLock(spin)
|
|
|
|
#define pthread_spin_trylock(spin) sc_mutex_trylock(spin)
|
|
|
|
#define pthread_spin_trylock(spin) SCMutexTrylock(spin)
|
|
|
|
#define pthread_spin_unlock(spin) sc_mutex_unlock(spin)
|
|
|
|
#define pthread_spin_unlock(spin) SCMutexUnlock(spin)
|
|
|
|
#define pthread_spin_destroy(spin) sc_mutex_destroy(spin)
|
|
|
|
#define pthread_spin_destroy(spin) SCMutexDestroy(spin)
|
|
|
|
#endif /* End Spin not supported */
|
|
|
|
#endif /* End Spin not supported */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DBG_THREADS
|
|
|
|
#ifdef DBG_THREADS
|
|
|
|
#define sc_spin_lock_dbg(spin) ({ \
|
|
|
|
#define SCSpinLock_dbg(spin) ({ \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") locking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") locking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
|
|
|
|
int ret = pthread_spin_lock(spin); \
|
|
|
|
int ret = pthread_spin_lock(spin); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
@ -171,7 +171,7 @@
|
|
|
|
ret; \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_spin_trylock_dbg(spin) ({ \
|
|
|
|
#define SCSpinTrylock_dbg(spin) ({ \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
|
|
|
|
int ret = pthread_spin_trylock(spin); \
|
|
|
|
int ret = pthread_spin_trylock(spin); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") trylocked spin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
@ -189,7 +189,7 @@
|
|
|
|
ret; \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_spin_unlock_dbg(spin) ({ \
|
|
|
|
#define SCSpinUnlock_dbg(spin) ({ \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlocking spin %p\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
|
|
|
|
int ret = pthread_spin_unlock(spin); \
|
|
|
|
int ret = pthread_spin_unlock(spin); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlockedspin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") unlockedspin %p ret %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
@ -204,7 +204,7 @@
|
|
|
|
ret; \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_spin_init_dbg(spin, spin_attr) ({ \
|
|
|
|
#define SCSpinInit_dbg(spin, spin_attr) ({ \
|
|
|
|
int ret = pthread_spin_init(spin, spin_attr); \
|
|
|
|
int ret = pthread_spin_init(spin, spin_attr); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") spinlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") spinlock %p initialization returned %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
switch (ret) { \
|
|
|
|
switch (ret) { \
|
|
|
|
@ -224,7 +224,7 @@
|
|
|
|
ret; \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_spin_destroy_dbg(spin) ({ \
|
|
|
|
#define SCSpinDestroy_dbg(spin) ({ \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p waiting\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p waiting\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin); \
|
|
|
|
int ret = pthread_spin_destroy(spin); \
|
|
|
|
int ret = pthread_spin_destroy(spin); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p passed %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
printf("%16s(%s:%d): (thread:%"PRIuMAX") condition %p passed %" PRId32 "\n", __FUNCTION__, __FILE__, __LINE__, (uintmax_t)pthread_self(), spin, ret); \
|
|
|
|
@ -245,17 +245,17 @@
|
|
|
|
ret; \
|
|
|
|
ret; \
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#define sc_spin_lock sc_spin_lock_dbg
|
|
|
|
#define SCSpinLock SCSpinLock_dbg
|
|
|
|
#define sc_spin_trylock sc_spin_trylock_dbg
|
|
|
|
#define SCSpinTrylock SCSpinTrylock_dbg
|
|
|
|
#define sc_spin_unlock sc_spin_unlock_dbg
|
|
|
|
#define SCSpinUnlock SCSpinUnlock_dbg
|
|
|
|
#define sc_spin_init sc_spin_init_dbg
|
|
|
|
#define SCSpinInit SCSpinInit_dbg
|
|
|
|
#define sc_spin_destroy sc_spin_destroy_dbg
|
|
|
|
#define SCSpinDestroy SCSpinDestroy_dbg
|
|
|
|
#else /* if no dbg threads defined... */
|
|
|
|
#else /* if no dbg threads defined... */
|
|
|
|
#define sc_spin_lock(spin) pthread_spin_lock(spin)
|
|
|
|
#define SCSpinLock(spin) pthread_spin_lock(spin)
|
|
|
|
#define sc_spin_trylock(spin) pthread_spin_trylock(spin)
|
|
|
|
#define SCSpinTrylock(spin) pthread_spin_trylock(spin)
|
|
|
|
#define sc_spin_unlock(spin) pthread_spin_unlock(spin)
|
|
|
|
#define SCSpinUnlock(spin) pthread_spin_unlock(spin)
|
|
|
|
#define sc_spin_init(spin, spin_attr) pthread_spin_init(spin, spin_attr)
|
|
|
|
#define SCSpinInit(spin, spin_attr) pthread_spin_init(spin, spin_attr)
|
|
|
|
#define sc_spin_destroy(spin) pthread_spin_destroy(spin)
|
|
|
|
#define SCSpinDestroy(spin) pthread_spin_destroy(spin)
|
|
|
|
#endif /* DBG_THREADS */
|
|
|
|
#endif /* DBG_THREADS */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|