#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);
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;
}
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);
}
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);
}
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;
}