diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2010-09-03 22:09:56 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2010-09-03 22:15:52 +0200 |
commit | ec61e75b5228b941b62110752c57a145a42e8214 (patch) | |
tree | e5c02feb53ca94d82c9263e040ceb0e47f40eede | |
parent | 2de160b60e65efe83dba097574abd5454cb870a9 (diff) |
WAIT_DEBUG: permit to get function names instead of threads
From the idea of Sergio Lopez.
* libthreads/cthreads.h [WAIT_FUNC_DEBUG] (mutex): Replace struct
cthread *holder field with const char *fname.
(WAIT_CLEAR_DEBUG, WAIT_SET_DEBUG): New macros which clear and set fname
or holder according to WAIT_FUNC_DEBUG and WAIT_DEBUG being defined.
(mutex_init, mutex_unlock): Call WAIT_CLEAR_DEBUG in all cases instead of
setting the `holder' field according to WAIT_DEBUG being defined
(mutex_lock): Call WAIT_SET_DEBUG in all cases instead of setting the `holder'
field according to WAIT_DEBUG being defined.
-rw-r--r-- | libthreads/cthreads.h | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/libthreads/cthreads.h b/libthreads/cthreads.h index d3b6c290..2c35e700 100644 --- a/libthreads/cthreads.h +++ b/libthreads/cthreads.h @@ -269,6 +269,11 @@ typedef void *any_t; /* XXX - obsolete, should be deleted. */ #define FALSE 0 #endif +/* Enable mutex holder debugging */ +/* #define WAIT_DEBUG */ +/* Record function name instead of thread pointer */ +/* #define WAIT_FUNC_DEBUG */ + /* * C Threads package initialization. */ @@ -377,9 +382,26 @@ typedef struct mutex { const char *name; struct cthread_queue queue; /* holder is for WAIT_DEBUG. Not ifdeffed to keep size constant. */ +#ifdef WAIT_FUNC_DEBUG + const char *fname; +#else /* WAIT_FUNC_DEBUG */ struct cthread *holder; +#endif /* WAIT_FUNC_DEBUG */ } *mutex_t; +#ifdef WAIT_DEBUG +#ifdef WAIT_FUNC_DEBUG +#define WAIT_CLEAR_DEBUG(m) (m)->fname = 0 +#define WAIT_SET_DEBUG(m) (m)->fname = __FUNCTION__ +#else /* WAIT_FUNC_DEBUG */ +#define WAIT_CLEAR_DEBUG(m) (m)->holder = 0 +#define WAIT_SET_DEBUG(m) (m)->holder = cthread_self() +#endif /* WAIT_FUNC_DEBUG */ +#else /* WAIT_DEBUG */ +#define WAIT_CLEAR_DEBUG(m) (void) 0 +#define WAIT_SET_DEBUG(m) (void) 0 +#endif /* WAIT_DEBUG */ + /* Rearranged accordingly for GNU: */ #define MUTEX_INITIALIZER { SPIN_LOCK_INITIALIZER, SPIN_LOCK_INITIALIZER, 0, QUEUE_INITIALIZER, } #define MUTEX_NAMED_INITIALIZER(Name) { SPIN_LOCK_INITIALIZER, SPIN_LOCK_INITIALIZER, Name, QUEUE_INITIALIZER, } @@ -390,7 +412,7 @@ typedef struct mutex { spin_lock_init(&(m)->lock); \ cthread_queue_init(&(m)->queue); \ spin_lock_init(&(m)->held); \ - (m)->holder = 0; \ + WAIT_CLEAR_DEBUG(m); \ MACRO_END #define mutex_set_name(m, x) ((m)->name = (x)) #define mutex_name(m) ((m)->name != 0 ? (m)->name : "?") @@ -398,28 +420,12 @@ typedef struct mutex { #define mutex_free(m) free((m)) #define mutex_try_lock(m) spin_try_lock(&(m)->held) -#if defined(WAIT_DEBUG) -#define mutex_lock(m) \ - MACRO_BEGIN \ - if (!spin_try_lock(&(m)->held)) { \ - __mutex_lock_solid(m); \ - } \ - (m)->holder = cthread_self(); \ - MACRO_END -#define mutex_unlock(m) \ - MACRO_BEGIN \ - if (spin_unlock(&(m)->held), \ - cthread_queue_head(&(m)->queue, vm_offset_t) != 0) { \ - __mutex_unlock_solid(m); \ - } \ - (m)->holder = 0; \ - MACRO_END -#else /* defined(WAIT_DEBUG */ #define mutex_lock(m) \ MACRO_BEGIN \ if (!spin_try_lock(&(m)->held)) { \ __mutex_lock_solid(m); \ } \ + WAIT_SET_DEBUG(m); \ MACRO_END #define mutex_unlock(m) \ MACRO_BEGIN \ @@ -427,8 +433,8 @@ typedef struct mutex { cthread_queue_head(&(m)->queue, vm_offset_t) != 0) { \ __mutex_unlock_solid(m); \ } \ + WAIT_CLEAR_DEBUG(m); \ MACRO_END -#endif /* defined(WAIT_DEBUG) */ /* * Condition variables. */ |