enable thread debugging

This commit is contained in:
Vítor Santos Costa
2013-11-12 08:34:26 +00:00
parent 2314efdc6c
commit e813c75814
5 changed files with 168 additions and 115 deletions

View File

@@ -20,8 +20,17 @@
#define INIT_LOCK(LOCK_VAR) pthread_mutex_init(&(LOCK_VAR), NULL)
#define DESTROY_LOCK(LOCK_VAR) pthread_mutex_destroy(&(LOCK_VAR))
#define TRY_LOCK(LOCK_VAR) pthread_mutex_trylock(&(LOCK_VAR))
#if DEBUG_LOCKS
#define LOCK(LOCK_VAR) if (debug_locks) fprintf(stderr,"[%d] %s:%d: LOCK(%p)\n", (int)pthread_self(), \
__BASE_FILE__, __LINE__,&(LOCK_VAR)); \
pthread_mutex_lock(&(LOCK_VAR))
#define UNLOCK(LOCK_VAR) if (debug_locks) fprintf(stderr,"[%d] %s:%d: UNLOCK(%p)\n", (int)pthread_self(), \
__BASE_FILE__, __LINE__,&(LOCK_VAR)); \
pthread_mutex_unlock(&(LOCK_VAR))
#else
#define LOCK(LOCK_VAR) pthread_mutex_lock(&(LOCK_VAR))
#define UNLOCK(LOCK_VAR) pthread_mutex_unlock(&(LOCK_VAR))
#endif
static inline int
xIS_LOCKED(pthread_mutex_t *LOCK_VAR) {
if (pthread_mutex_trylock(LOCK_VAR) == 0) {
@@ -47,3 +56,32 @@ xIS_UNLOCKED(pthread_mutex_t *LOCK_VAR) {
#define READ_UNLOCK(X) pthread_rwlock_unlock(&(X))
#define WRITE_LOCK(X) pthread_rwlock_wrlock(&(X))
#define WRITE_UNLOCK(X) pthread_rwlock_unlock(&(X))
#if THREADS
/* pthread mutex */
#if DEBUG_LOCKS
#define MUTEX_LOCK(LOCK_VAR) if (debug_locks) fprintf(stderr,"[%d] %s:%d: MULOCK(%p)\n", (int)pthread_self(), \
__BASE_FILE__, __LINE__,(LOCK_VAR)); \
pthread_mutex_lock((LOCK_VAR))
#define MUTEX_TRYLOCK(LOCK_VAR) pthread_mutex_TRYlock((LOCK_VAR))
#define MUTEX_UNLOCK(LOCK_VAR) if (debug_locks) fprintf(stderr,"[%d] %s:%d: UNMULOCK(%p)\n", (int)pthread_self(), \
__BASE_FILE__, __LINE__,(LOCK_VAR)); \
pthread_mutex_unlock((LOCK_VAR))
#else
#define MUTEX_LOCK(LOCK_VAR) pthread_mutex_lock((LOCK_VAR))
#define MUTEX_TRYLOCK(LOCK_VAR) pthread_mutex_trylock((LOCK_VAR))
#define MUTEX_UNLOCK(LOCK_VAR) pthread_mutex_unlock((LOCK_VAR))
#endif
#else
#define MUTEX_LOCK(LOCK_VAR)
#define MUTEX_TRYLOCK(LOCK_VAR)
#define MUTEX_UNLOCK(LOCK_VAR)
#endif