]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - thread_win.c
thread_pthread now uses recursive mutex (THREADRECURSIVE)
[xonotic/darkplaces.git] / thread_win.c
index a6ae7b3c13b6957488d82b161c1673b0751bc33a..893e8306048ede60d060f24efbe3e5c9b8669a23 100644 (file)
@@ -20,7 +20,7 @@ void *_Thread_CreateMutex(const char *filename, int fileline)
 {
        void *mutex = (void *)CreateMutex(NULL, FALSE, NULL);
 #ifdef THREADDEBUG
-       Sys_PrintfToTerminal("%p create %s:%i\n" , mutex, filename, fileline);
+       Sys_PrintfToTerminal("%p mutex create %s:%i\n" , mutex, filename, fileline);
 #endif
        return mutex;
 }
@@ -28,7 +28,7 @@ void *_Thread_CreateMutex(const char *filename, int fileline)
 void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline)
 {
 #ifdef THREADDEBUG
-       Sys_PrintfToTerminal("%p destroy %s:%i\n", mutex, filename, fileline);
+       Sys_PrintfToTerminal("%p mutex destroy %s:%i\n", mutex, filename, fileline);
 #endif
        CloseHandle(mutex);
 }
@@ -36,7 +36,7 @@ void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline)
 int _Thread_LockMutex(void *mutex, const char *filename, int fileline)
 {
 #ifdef THREADDEBUG
-       Sys_PrintfToTerminal("%p lock %s:%i\n"   , mutex, filename, fileline);
+       Sys_PrintfToTerminal("%p mutex lock %s:%i\n"   , mutex, filename, fileline);
 #endif
        return (WaitForSingleObject(mutex, INFINITE) == WAIT_FAILED) ? -1 : 0;
 }
@@ -44,7 +44,7 @@ int _Thread_LockMutex(void *mutex, const char *filename, int fileline)
 int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline)
 {
 #ifdef THREADDEBUG
-       Sys_PrintfToTerminal("%p unlock %s:%i\n" , mutex, filename, fileline);
+       Sys_PrintfToTerminal("%p mutex unlock %s:%i\n" , mutex, filename, fileline);
 #endif
        return (ReleaseMutex(mutex) == FALSE) ? -1 : 0;
 }
@@ -102,7 +102,7 @@ typedef struct thread_cond_s
 }
 thread_cond_t;
 
-void *Thread_CreateCond(void)
+void *_Thread_CreateCond(const char *filename, int fileline)
 {
        thread_cond_t *c = (thread_cond_t *)calloc(sizeof(*c), 1);
        c->mutex = CreateMutex(NULL, FALSE, NULL);
@@ -110,21 +110,30 @@ void *Thread_CreateCond(void)
        c->done = Thread_CreateSemaphore(0);
        c->waiting = 0;
        c->signals = 0;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p cond create %s:%i\n"   , c, filename, fileline);
+#endif
        return c;
 }
 
-void Thread_DestroyCond(void *cond)
+void _Thread_DestroyCond(void *cond, const char *filename, int fileline)
 {
        thread_cond_t *c = (thread_cond_t *)cond;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p cond destroy %s:%i\n"   , cond, filename, fileline);
+#endif
        Thread_DestroySemaphore(c->sem);
        Thread_DestroySemaphore(c->done);
        CloseHandle(c->mutex);
 }
 
-int Thread_CondSignal(void *cond)
+int _Thread_CondSignal(void *cond, const char *filename, int fileline)
 {
        thread_cond_t *c = (thread_cond_t *)cond;
        int n;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p cond signal %s:%i\n"   , cond, filename, fileline);
+#endif
        WaitForSingleObject(c->mutex, INFINITE);
        n = c->waiting - c->signals;
        if (n > 0)
@@ -138,11 +147,14 @@ int Thread_CondSignal(void *cond)
        return 0;
 }
 
-int Thread_CondBroadcast(void *cond)
+int _Thread_CondBroadcast(void *cond, const char *filename, int fileline)
 {
        thread_cond_t *c = (thread_cond_t *)cond;
        int i = 0;
        int n = 0;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p cond broadcast %s:%i\n"   , cond, filename, fileline);
+#endif
        WaitForSingleObject(c->mutex, INFINITE);
        n = c->waiting - c->signals;
        if (n > 0)
@@ -157,10 +169,13 @@ int Thread_CondBroadcast(void *cond)
        return 0;
 }
 
-int Thread_CondWait(void *cond, void *mutex)
+int _Thread_CondWait(void *cond, void *mutex, const char *filename, int fileline)
 {
        thread_cond_t *c = (thread_cond_t *)cond;
        int waitresult;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p cond wait %s:%i\n"   , cond, filename, fileline);
+#endif
 
        WaitForSingleObject(c->mutex, INFINITE);
        c->waiting++;
@@ -202,9 +217,12 @@ unsigned int __stdcall Thread_WrapperFunc(void *d)
        return w->result;
 }
 
-void *Thread_CreateThread(int (*fn)(void *), void *data)
+void *_Thread_CreateThread(int (*fn)(void *), void *data, const char *filename, int fileline)
 {
        threadwrapper_t *w = (threadwrapper_t *)calloc(sizeof(*w), 1);
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p thread create %s:%i\n"   , w, filename, fileline);
+#endif
        w->fn = fn;
        w->data = data;
        w->threadid = 0;
@@ -213,9 +231,12 @@ void *Thread_CreateThread(int (*fn)(void *), void *data)
        return (void *)w;
 }
 
-int Thread_WaitThread(void *d, int retval)
+int _Thread_WaitThread(void *d, int retval, const char *filename, int fileline)
 {
        threadwrapper_t *w = (threadwrapper_t *)d;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p thread wait %s:%i\n"   , w, filename, fileline);
+#endif
        WaitForSingleObject(w->handle, INFINITE);
        CloseHandle(w->handle);
        retval = w->result;