]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
added debug prints (enabled if you define THREADDEBUG) for debugging
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 25 Oct 2011 02:14:17 +0000 (02:14 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 25 Oct 2011 02:14:17 +0000 (02:14 +0000)
mutex locks

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11470 d7cf8633-e32d-0410-b094-e92efae38249

thread.h
thread_null.c
thread_pthread.c
thread_sdl.c
thread_win.c

index 590da9771ff4a52f508554000ed49828ff928dfc..216f690668afa7d804ec3182e7b0df48ac90a3ac 100644 (file)
--- 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);
index 5d788a49ba99ada73e63a23a7ca1279a9f16ba69..8a75e2461a4641f5f62fd76fb75a9f1a8f60ed96 100644 (file)
@@ -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;
 }
 
index d394b6db08ac5f6da886016cdee3d4fb6c862050..69558da5cb959411c2c145a4a3092d92dd333dfe 100644 (file)
@@ -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);
 }
 
index 5272221e946206fe6955725a2a447dae51d9f274..d857445a1a4a07b4492418e8d288ace4e842cae0 100644 (file)
@@ -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);
 }
 
index a55e6b4cdac01e7acba1ec29933e971f842b5add..a882f80d00f14d1f7df1deec61a4a82ed08863c3 100644 (file)
@@ -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;
 }