From: havoc Date: Tue, 25 Oct 2011 02:14:17 +0000 (+0000) Subject: added debug prints (enabled if you define THREADDEBUG) for debugging X-Git-Tag: xonotic-v0.6.0~163^2~87 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=276e463972834a60d2c8cc23de2a65af8589a8c6;p=xonotic%2Fdarkplaces.git added debug prints (enabled if you define THREADDEBUG) for debugging mutex locks git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11470 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/thread.h b/thread.h index 590da977..216f6906 100644 --- a/thread.h +++ b/thread.h @@ -1,12 +1,19 @@ #ifndef THREAD_H +//#define THREADDEBUG + +#define Thread_CreateMutex() (_Thread_CreateMutex(__FILE__, __LINE__)) +#define Thread_DestroyMutex(m) (_Thread_DestroyMutex(m, __FILE__, __LINE__)) +#define Thread_LockMutex(m) (_Thread_LockMutex(m, __FILE__, __LINE__)) +#define Thread_UnlockMutex(m) (_Thread_UnlockMutex(m, __FILE__, __LINE__)) + int Thread_Init(void); void Thread_Shutdown(void); qboolean Thread_HasThreads(void); -void *Thread_CreateMutex(void); -void Thread_DestroyMutex(void *mutex); -int Thread_LockMutex(void *mutex); -int Thread_UnlockMutex(void *mutex); +void *_Thread_CreateMutex(const char *filename, int fileline); +void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline); +int _Thread_LockMutex(void *mutex, const char *filename, int fileline); +int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline); void *Thread_CreateCond(void); void Thread_DestroyCond(void *cond); int Thread_CondSignal(void *cond); diff --git a/thread_null.c b/thread_null.c index 5d788a49..8a75e246 100644 --- a/thread_null.c +++ b/thread_null.c @@ -15,22 +15,34 @@ qboolean Thread_HasThreads(void) return false; } -void *Thread_CreateMutex(void) +void *_Thread_CreateMutex(const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p create %s:%i\n" , mutex, filename, fileline); +#endif return NULL; } -void Thread_DestroyMutex(void *mutex) +void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p destroy %s:%i\n", mutex, filename, fileline); +#endif } -int Thread_LockMutex(void *mutex) +int _Thread_LockMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p lock %s:%i\n" , mutex, filename, fileline); +#endif return -1; } -int Thread_UnlockMutex(void *mutex) +int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p unlock %s:%i\n" , mutex, filename, fileline); +#endif return -1; } diff --git a/thread_pthread.c b/thread_pthread.c index d394b6db..69558da5 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -17,29 +17,41 @@ qboolean Thread_HasThreads(void) return true; } -void *Thread_CreateMutex(void) +void *_Thread_CreateMutex(const char *filename, int fileline) { pthread_mutex_t *mutexp = (pthread_mutex_t *) Z_Malloc(sizeof(pthread_mutex_t)); +#ifdef THREADDEBUG + printf("%p create %s:%i\n" , mutexp, filename, fileline); +#endif pthread_mutex_init(mutexp, NULL); return mutexp; } -void Thread_DestroyMutex(void *mutex) +void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline) { pthread_mutex_t *mutexp = (pthread_mutex_t *) mutex; +#ifdef THREADDEBUG + printf("%p destroy %s:%i\n", mutex, filename, fileline); +#endif pthread_mutex_destroy(mutexp); Z_Free(mutexp); } -int Thread_LockMutex(void *mutex) +int _Thread_LockMutex(void *mutex, const char *filename, int fileline) { pthread_mutex_t *mutexp = (pthread_mutex_t *) mutex; +#ifdef THREADDEBUG + printf("%p lock %s:%i\n" , mutex, filename, fileline); +#endif return pthread_mutex_lock(mutexp); } -int Thread_UnlockMutex(void *mutex) +int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline) { pthread_mutex_t *mutexp = (pthread_mutex_t *) mutex; +#ifdef THREADDEBUG + printf("%p unlock %s:%i\n" , mutex, filename, fileline); +#endif return pthread_mutex_unlock(mutexp); } diff --git a/thread_sdl.c b/thread_sdl.c index 5272221e..d857445a 100644 --- a/thread_sdl.c +++ b/thread_sdl.c @@ -17,23 +17,36 @@ qboolean Thread_HasThreads(void) return true; } -void *Thread_CreateMutex(void) +void *_Thread_CreateMutex(const char *filename, int fileline) { - return SDL_CreateMutex(); + void *mutex = SDL_CreateMutex(); +#ifdef THREADDEBUG + printf("%p create %s:%i\n" , mutex, filename, fileline); +#endif + return mutex; } -void Thread_DestroyMutex(void *mutex) +void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p destroy %s:%i\n", mutex, filename, fileline); +#endif SDL_DestroyMutex((SDL_mutex *)mutex); } -int Thread_LockMutex(void *mutex) +int _Thread_LockMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p lock %s:%i\n" , mutex, filename, fileline); +#endif return SDL_LockMutex((SDL_mutex *)mutex); } -int Thread_UnlockMutex(void *mutex) +int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p unlock %s:%i\n" , mutex, filename, fileline); +#endif return SDL_UnlockMutex((SDL_mutex *)mutex); } diff --git a/thread_win.c b/thread_win.c index a55e6b4c..a882f80d 100644 --- a/thread_win.c +++ b/thread_win.c @@ -16,23 +16,36 @@ qboolean Thread_HasThreads(void) return true; } -void *Thread_CreateMutex(void) +void *_Thread_CreateMutex(const char *filename, int fileline) { - return (void *)CreateMutex(NULL, FALSE, NULL); + void *mutex = (void *)CreateMutex(NULL, FALSE, NULL); +#ifdef THREADDEBUG + printf("%p create %s:%i\n" , mutex, filename, fileline); +#endif + return mutex; } -void Thread_DestroyMutex(void *mutex) +void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p destroy %s:%i\n", mutex, filename, fileline); +#endif CloseHandle(mutex); } -int Thread_LockMutex(void *mutex) +int _Thread_LockMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p lock %s:%i\n" , mutex, filename, fileline); +#endif return (WaitForSingleObject(mutex, INFINITE) == WAIT_FAILED) ? -1 : 0; } -int Thread_UnlockMutex(void *mutex) +int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline) { +#ifdef THREADDEBUG + printf("%p unlock %s:%i\n" , mutex, filename, fileline); +#endif return (ReleaseMutex(mutex) == FALSE) ? -1 : 0; }