Mercurial > hg > dmlib
diff dmlib.h @ 294:dd9809a93425
Improve mutex debugging facilities.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 11 Oct 2012 16:04:02 +0300 |
parents | e2f286781180 |
children | 036fde2fd630 |
line wrap: on
line diff
--- a/dmlib.h Thu Oct 11 16:01:14 2012 +0300 +++ b/dmlib.h Thu Oct 11 16:04:02 2012 +0300 @@ -71,14 +71,6 @@ #define DMRES_RES_FILE "res.txt" // Resource data file -// Mutexes -#define DMMutex SDL_mutex -#define dmCreateMutex() SDL_CreateMutex() -#define dmDestroyMutex(x) SDL_DestroyMutex(x) -#define dmMutexLock(x) SDL_mutexP(x) -#define dmMutexUnlock(x) SDL_mutexV(x) - - /* Define a boolean type */ #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL) @@ -381,6 +373,42 @@ char * dm_strdup_printf(const char *, ...); +/* Mutexes + */ +#ifdef DM_MUTEX_DEBUG + +typedef struct +{ + BOOL used; + Uint32 id; + int state; +} DMMutexLock; + +typedef struct +{ + char *cr_file; + int cr_line; + SDL_mutex *m; + DMMutexLock locks[8]; +} DMMutex; + +#define dmMutexLock(x) dmDOMutexLock(x, __FILE__, (int) __LINE__) +#define dmMutexUnlock(x) dmDOMutexUnlock(x, __FILE__, (int) __LINE__) +#define dmCreateMutex(x) dmDOCreateMutex(__FILE__, (int) __LINE__) + +int dmDOMutexLock(DMMutex *mutex, const char *file, const int line); +int dmDOMutexUnlock(DMMutex *mutex, const char *file, const int line); +DMMutex * dmDOCreateMutex(const char *file, const int line); +void dmDestroyMutex(DMMutex *mutex); + +#else +#define DMMutex SDL_mutex +#define dmCreateMutex() SDL_CreateMutex() +#define dmDestroyMutex(x) SDL_DestroyMutex(x) +#define dmMutexLock(x) SDL_mutexP(x) +#define dmMutexUnlock(x) SDL_mutexV(x) +#endif + /* Endianess swapping macros */ #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \