if (!svs.threaded)
return;
svs.threadstop = true;
- Thread_WaitThread(svs.thread, 0);
+ Thread_WaitThread(svs.thread, NULL);
Thread_DestroyMutex(svs.threadmutex);
svs.threaded = false;
}
#ifndef THREAD_H
+#define THREAD_H
-// enable Sys_PrintfToTerminal calls on nearly every threading call
-//#define THREADDEBUG
+// disable threads
//#define THREADDISABLE
+
// use recursive mutex (non-posix) extensions in thread_pthread
#define THREADRECURSIVE
-#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__))
-#define Thread_CreateCond() (_Thread_CreateCond(__FILE__, __LINE__))
-#define Thread_DestroyCond(cond) (_Thread_DestroyCond(cond, __FILE__, __LINE__))
-#define Thread_CondSignal(cond) (_Thread_CondSignal(cond, __FILE__, __LINE__))
-#define Thread_CondBroadcast(cond) (_Thread_CondBroadcast(cond, __FILE__, __LINE__))
-#define Thread_CondWait(cond, mutex) (_Thread_CondWait(cond, mutex, __FILE__, __LINE__))
-#define Thread_CreateThread(fn, data) (_Thread_CreateThread(fn, data, __FILE__, __LINE__))
-#define Thread_WaitThread(thread, retval) (_Thread_WaitThread(thread, retval, __FILE__, __LINE__))
-#define Thread_CreateBarrier(count) (_Thread_CreateBarrier(count, __FILE__, __LINE__))
-#define Thread_DestroyBarrier(barrier) (_Thread_DestroyBarrier(barrier, __FILE__, __LINE__))
-#define Thread_WaitBarrier(barrier) (_Thread_WaitBarrier(barrier, __FILE__, __LINE__))
-
int Thread_Init(void);
void Thread_Shutdown(void);
qboolean Thread_HasThreads(void);
-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(const char *filename, int fileline);
-void _Thread_DestroyCond(void *cond, const char *filename, int fileline);
-int _Thread_CondSignal(void *cond, const char *filename, int fileline);
-int _Thread_CondBroadcast(void *cond, const char *filename, int fileline);
-int _Thread_CondWait(void *cond, void *mutex, const char *filename, int fileline);
-void *_Thread_CreateThread(int (*fn)(void *), void *data, const char *filename, int fileline);
-int _Thread_WaitThread(void *thread, int retval, const char *filename, int fileline);
-void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline);
-void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline);
-void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline);
+void *Thread_CreateMutex(void);
+void Thread_DestroyMutex(void *mutex);
+int Thread_LockMutex(void *mutex);
+int Thread_UnlockMutex(void *mutex);
+void *Thread_CreateCond(void);
+void Thread_DestroyCond(void *cond);
+int Thread_CondSignal(void *cond);
+int Thread_CondBroadcast(void *cond);
+int Thread_CondWait(void *cond, void *mutex);
+void *Thread_CreateThread(int (*fn)(void *), void *data);
+void Thread_WaitThread(void *thread, int *retval);
+void *Thread_CreateBarrier(unsigned int count);
+void Thread_DestroyBarrier(void *barrier);
+void Thread_WaitBarrier(void *barrier);
+void Thread_SetThreadPriorityLow(void);
+void Thread_SetThreadPriorityNormal(void);
+void Thread_SetThreadPriorityHigh(void);
#endif
return false;
}
-void *_Thread_CreateMutex(const char *filename, int fileline)
+void *Thread_CreateMutex(void)
{
return NULL;
}
-void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline)
+void Thread_DestroyMutex(void *mutex)
{
}
-int _Thread_LockMutex(void *mutex, const char *filename, int fileline)
+int Thread_LockMutex(void *mutex)
{
return -1;
}
-int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline)
+int Thread_UnlockMutex(void *mutex)
{
return -1;
}
-void *_Thread_CreateCond(const char *filename, int fileline)
+void *Thread_CreateCond(void)
{
return NULL;
}
-void _Thread_DestroyCond(void *cond, const char *filename, int fileline)
+void Thread_DestroyCond(void *cond)
{
}
-int _Thread_CondSignal(void *cond, const char *filename, int fileline)
+int Thread_CondSignal(void *cond)
{
return -1;
}
-int _Thread_CondBroadcast(void *cond, const char *filename, int fileline)
+int Thread_CondBroadcast(void *cond)
{
return -1;
}
-int _Thread_CondWait(void *cond, void *mutex, const char *filename, int fileline)
+int Thread_CondWait(void *cond, void *mutex)
{
return -1;
}
-void *_Thread_CreateThread(int (*fn)(void *), void *data, const char *filename, int fileline)
+void *Thread_CreateThread(int (*fn)(void *), void *data)
{
return NULL;
}
-int _Thread_WaitThread(void *thread, int retval, const char *filename, int fileline)
+void Thread_WaitThread(void *thread, int *retval)
{
- return retval;
}
-void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+void *Thread_CreateBarrier(unsigned int count)
{
return NULL;
}
-void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+void Thread_DestroyBarrier(void *barrier)
{
}
-void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+void Thread_WaitBarrier(void *barrier)
{
}
+
+void Thread_SetThreadPriorityLow(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+}
+
+void Thread_SetThreadPriorityNormal(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+}
+
+void Thread_SetThreadPriorityHigh(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+}
return true;
}
-void *_Thread_CreateMutex(const char *filename, int fileline)
+void *Thread_CreateMutex(void)
{
#ifdef THREADRECURSIVE
pthread_mutexattr_t attr;
#endif
- pthread_mutex_t *mutexp = (pthread_mutex_t *) Z_Malloc(sizeof(pthread_mutex_t));
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex create %s:%i\n" , mutexp, filename, fileline);
-#endif
+ pthread_mutex_t *mutexp = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
#ifdef THREADRECURSIVE
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
return mutexp;
}
-void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline)
+void Thread_DestroyMutex(void *mutex)
{
pthread_mutex_t *mutexp = (pthread_mutex_t *) mutex;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex destroy %s:%i\n", mutex, filename, fileline);
-#endif
pthread_mutex_destroy(mutexp);
- Z_Free(mutexp);
+ free(mutexp);
}
-int _Thread_LockMutex(void *mutex, const char *filename, int fileline)
+int Thread_LockMutex(void *mutex)
{
pthread_mutex_t *mutexp = (pthread_mutex_t *) mutex;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex lock %s:%i\n" , mutex, filename, fileline);
-#endif
return pthread_mutex_lock(mutexp);
}
-int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline)
+int Thread_UnlockMutex(void *mutex)
{
pthread_mutex_t *mutexp = (pthread_mutex_t *) mutex;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex unlock %s:%i\n" , mutex, filename, fileline);
-#endif
return pthread_mutex_unlock(mutexp);
}
-void *_Thread_CreateCond(const char *filename, int fileline)
+void *Thread_CreateCond(void)
{
- pthread_cond_t *condp = (pthread_cond_t *) Z_Malloc(sizeof(pthread_cond_t));
+ pthread_cond_t *condp = (pthread_cond_t *) malloc(sizeof(pthread_cond_t));
pthread_cond_init(condp, NULL);
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond create %s:%i\n" , condp, filename, fileline);
-#endif
return condp;
}
-void _Thread_DestroyCond(void *cond, const char *filename, int fileline)
+void Thread_DestroyCond(void *cond)
{
pthread_cond_t *condp = (pthread_cond_t *) cond;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond destroy %s:%i\n" , cond, filename, fileline);
-#endif
pthread_cond_destroy(condp);
- Z_Free(condp);
+ free(condp);
}
-int _Thread_CondSignal(void *cond, const char *filename, int fileline)
+int Thread_CondSignal(void *cond)
{
pthread_cond_t *condp = (pthread_cond_t *) cond;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond signal %s:%i\n" , cond, filename, fileline);
-#endif
return pthread_cond_signal(condp);
}
-int _Thread_CondBroadcast(void *cond, const char *filename, int fileline)
+int Thread_CondBroadcast(void *cond)
{
pthread_cond_t *condp = (pthread_cond_t *) cond;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond broadcast %s:%i\n" , cond, filename, fileline);
-#endif
return pthread_cond_broadcast(condp);
}
-int _Thread_CondWait(void *cond, void *mutex, const char *filename, int fileline)
+int Thread_CondWait(void *cond, void *mutex)
{
pthread_cond_t *condp = (pthread_cond_t *) cond;
pthread_mutex_t *mutexp = (pthread_mutex_t *) mutex;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond wait %s:%i\n" , cond, filename, fileline);
-#endif
return pthread_cond_wait(condp, mutexp);
}
-void *_Thread_CreateThread(int (*fn)(void *), void *data, const char *filename, int fileline)
+void *Thread_CreateThread(int (*fn)(void *), void *data)
{
- pthread_t *threadp = (pthread_t *) Z_Malloc(sizeof(pthread_t));
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p thread create %s:%i\n" , threadp, filename, fileline);
-#endif
+ pthread_t *threadp = (pthread_t *) malloc(sizeof(pthread_t));
int r = pthread_create(threadp, NULL, (void * (*) (void *)) fn, data);
if(r)
{
- Z_Free(threadp);
+ free(threadp);
return NULL;
}
return threadp;
}
-int _Thread_WaitThread(void *thread, int retval, const char *filename, int fileline)
+void Thread_WaitThread(void *thread, int *retval)
{
+ union
+ {
+ void *p;
+ int i;
+ } status;
pthread_t *threadp = (pthread_t *) thread;
- void *status = (void *) (intptr_t) retval;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p thread wait %s:%i\n" , thread, filename, fileline);
-#endif
- pthread_join(*threadp, &status);
- Z_Free(threadp);
- return (int) (intptr_t) status;
+ pthread_join(*threadp, &status.p);
+ if(retval)
+ *retval = status.i;
+ free(threadp);
}
#ifdef PTHREAD_BARRIER_SERIAL_THREAD
-void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+void *Thread_CreateBarrier(unsigned int count)
{
- pthread_barrier_t *b = (pthread_barrier_t *) Z_Malloc(sizeof(pthread_barrier_t));
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
-#endif
+ pthread_barrier_t *b = (pthread_barrier_t *) malloc(sizeof(pthread_barrier_t));
pthread_barrier_init(b, NULL, count);
return (void *) b;
}
-void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+void Thread_DestroyBarrier(void *barrier)
{
pthread_barrier_t *b = (pthread_barrier_t *) barrier;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier destroy %s:%i\n", b, filename, fileline);
-#endif
pthread_barrier_destroy(b);
+ free(b); // Izy's Patch
}
-void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+void Thread_WaitBarrier(void *barrier)
{
pthread_barrier_t *b = (pthread_barrier_t *) barrier;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier wait %s:%i\n", b, filename, fileline);
-#endif
pthread_barrier_wait(b);
}
#else
void *cond;
} barrier_t;
-void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+void *Thread_CreateBarrier(unsigned int count)
{
- volatile barrier_t *b = (volatile barrier_t *) Z_Malloc(sizeof(barrier_t));
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
-#endif
+ volatile barrier_t *b = (volatile barrier_t *) malloc(sizeof(barrier_t));
b->needed = count;
b->called = 0;
b->mutex = Thread_CreateMutex();
return (void *) b;
}
-void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+void Thread_DestroyBarrier(void *barrier)
{
volatile barrier_t *b = (volatile barrier_t *) barrier;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier destroy %s:%i\n", b, filename, fileline);
-#endif
Thread_DestroyMutex(b->mutex);
Thread_DestroyCond(b->cond);
+ free((void*)b); // Izy's Patch
}
-void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+void Thread_WaitBarrier(void *barrier)
{
volatile barrier_t *b = (volatile barrier_t *) barrier;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier wait %s:%i\n", b, filename, fileline);
-#endif
Thread_LockMutex(b->mutex);
b->called++;
if (b->called == b->needed) {
Thread_UnlockMutex(b->mutex);
}
#endif
+
+
+void Thread_SetThreadPriorityLow(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+ pthread_attr_t attr;
+ int policy = 0;
+ int min_prio_for_policy;
+ pthread_attr_init(&attr);
+ pthread_attr_getschedpolicy(&attr, &policy);
+ min_prio_for_policy = sched_get_priority_min(policy);
+ pthread_setschedprio(pthread_self(), min_prio_for_policy);
+ pthread_attr_destroy(&attr);
+}
+
+void Thread_SetThreadPriorityNormal(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+ pthread_attr_t attr;
+ int policy = 0;
+ int min_prio_for_policy;
+ int max_prio_for_policy;
+ int normal_prio_for_policy;
+ pthread_attr_init(&attr);
+ pthread_attr_getschedpolicy(&attr, &policy);
+ min_prio_for_policy = sched_get_priority_min(policy);
+ max_prio_for_policy = sched_get_priority_max(policy);
+ if(min_prio_for_policy >= 0 && max_prio_for_policy >= 0)
+ normal_prio_for_policy = (max_prio_for_policy-min_prio_for_policy)/2+min_prio_for_policy;
+ else
+ if(min_prio_for_policy < 0 && max_prio_for_policy <= 0)
+ normal_prio_for_policy = (min_prio_for_policy-max_prio_for_policy)/2+max_prio_for_policy;
+ else
+ normal_prio_for_policy = (max_prio_for_policy+min_prio_for_policy)/2;
+ pthread_setschedprio(pthread_self(), normal_prio_for_policy);
+ pthread_attr_destroy(&attr);
+}
+
+void Thread_SetThreadPriorityHigh(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+ pthread_attr_t attr;
+ int policy = 0;
+ int max_prio_for_policy;
+ pthread_attr_init(&attr);
+ pthread_attr_getschedpolicy(&attr, &policy);
+ max_prio_for_policy = sched_get_priority_max(policy);
+ pthread_setschedprio(pthread_self(), max_prio_for_policy);
+ pthread_attr_destroy(&attr);
+}
#endif
}
-void *_Thread_CreateMutex(const char *filename, int fileline)
+void *Thread_CreateMutex(void)
{
void *mutex = SDL_CreateMutex();
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex create %s:%i\n" , mutex, filename, fileline);
-#endif
return mutex;
}
-void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline)
+void Thread_DestroyMutex(void *mutex)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex destroy %s:%i\n", mutex, filename, fileline);
-#endif
SDL_DestroyMutex((SDL_mutex *)mutex);
}
-int _Thread_LockMutex(void *mutex, const char *filename, int fileline)
+int Thread_LockMutex(void *mutex)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex lock %s:%i\n" , mutex, filename, fileline);
-#endif
return SDL_LockMutex((SDL_mutex *)mutex);
}
-int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline)
+int Thread_UnlockMutex(void *mutex)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex unlock %s:%i\n" , mutex, filename, fileline);
-#endif
return SDL_UnlockMutex((SDL_mutex *)mutex);
}
-void *_Thread_CreateCond(const char *filename, int fileline)
+void *Thread_CreateCond(void)
{
void *cond = (void *)SDL_CreateCond();
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond create %s:%i\n" , cond, filename, fileline);
-#endif
return cond;
}
-void _Thread_DestroyCond(void *cond, const char *filename, int fileline)
+void Thread_DestroyCond(void *cond)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond destroy %s:%i\n" , cond, filename, fileline);
-#endif
SDL_DestroyCond((SDL_cond *)cond);
}
-int _Thread_CondSignal(void *cond, const char *filename, int fileline)
+int Thread_CondSignal(void *cond)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond signal %s:%i\n" , cond, filename, fileline);
-#endif
return SDL_CondSignal((SDL_cond *)cond);
}
-int _Thread_CondBroadcast(void *cond, const char *filename, int fileline)
+int Thread_CondBroadcast(void *cond)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond broadcast %s:%i\n" , cond, filename, fileline);
-#endif
return SDL_CondBroadcast((SDL_cond *)cond);
}
-int _Thread_CondWait(void *cond, void *mutex, const char *filename, int fileline)
+int Thread_CondWait(void *cond, void *mutex)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p cond wait %s:%i\n" , cond, filename, fileline);
-#endif
return SDL_CondWait((SDL_cond *)cond, (SDL_mutex *)mutex);
}
-void *_Thread_CreateThread(int (*fn)(void *), void *data, const char *filename, int fileline)
+void *Thread_CreateThread(int (*fn)(void *), void *data)
{
#if SDL_MAJOR_VERSION == 1
void *thread = (void *)SDL_CreateThread(fn, data);
#else
- void *thread = (void *)SDL_CreateThread(fn, filename, data);
-#endif
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p thread create %s:%i\n" , thread, filename, fileline);
+ void *thread = (void *)SDL_CreateThread(fn, "", data);
#endif
return thread;
}
-int _Thread_WaitThread(void *thread, int retval, const char *filename, int fileline)
+void Thread_WaitThread(void *thread, int *retval)
{
- int status = retval;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p thread wait %s:%i\n" , thread, filename, fileline);
-#endif
- SDL_WaitThread((SDL_Thread *)thread, &status);
- return status;
+ SDL_WaitThread((SDL_Thread *)thread, retval);
}
// standard barrier implementation using conds and mutexes
void *cond;
} barrier_t;
-void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+void *Thread_CreateBarrier(unsigned int count)
{
- volatile barrier_t *b = (volatile barrier_t *) Z_Malloc(sizeof(barrier_t));
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
-#endif
+ volatile barrier_t *b = (volatile barrier_t *) malloc(sizeof(barrier_t));
b->needed = count;
b->called = 0;
b->mutex = Thread_CreateMutex();
return (void *) b;
}
-void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+void Thread_DestroyBarrier(void *barrier)
{
volatile barrier_t *b = (volatile barrier_t *) barrier;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier destroy %s:%i\n", b, filename, fileline);
-#endif
Thread_DestroyMutex(b->mutex);
Thread_DestroyCond(b->cond);
+ free((void*)b); // Izy's Patch
}
-void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+void Thread_WaitBarrier(void *barrier)
{
volatile barrier_t *b = (volatile barrier_t *) barrier;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier wait %s:%i\n", b, filename, fileline);
-#endif
Thread_LockMutex(b->mutex);
b->called++;
if (b->called == b->needed) {
}
Thread_UnlockMutex(b->mutex);
}
+
+void Thread_SetThreadPriorityLow(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+#if SDL_VERSION_ATLEAST(2,0,3)
+ SDL_SetThreadPriority(SDL_THREAD_PRIORITY_LOW);
+#endif
+}
+
+void Thread_SetThreadPriorityNormal(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+#if SDL_VERSION_ATLEAST(2,0,3)
+ SDL_SetThreadPriority(SDL_THREAD_PRIORITY_NORMAL);
+#endif
+}
+
+void Thread_SetThreadPriorityHigh(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+#if SDL_VERSION_ATLEAST(2,0,3)
+ SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
+#endif
+}
#endif
}
-void *_Thread_CreateMutex(const char *filename, int fileline)
+void *Thread_CreateMutex(void)
{
void *mutex = (void *)CreateMutex(NULL, FALSE, NULL);
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex create %s:%i\n" , mutex, filename, fileline);
-#endif
return mutex;
}
-void _Thread_DestroyMutex(void *mutex, const char *filename, int fileline)
+void Thread_DestroyMutex(void *mutex)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex destroy %s:%i\n", mutex, filename, fileline);
-#endif
CloseHandle(mutex);
}
-int _Thread_LockMutex(void *mutex, const char *filename, int fileline)
+int Thread_LockMutex(void *mutex)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex lock %s:%i\n" , mutex, filename, fileline);
-#endif
return (WaitForSingleObject(mutex, INFINITE) == WAIT_FAILED) ? -1 : 0;
}
-int _Thread_UnlockMutex(void *mutex, const char *filename, int fileline)
+int Thread_UnlockMutex(void *mutex)
{
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p mutex unlock %s:%i\n" , mutex, filename, fileline);
-#endif
return (ReleaseMutex(mutex) == FALSE) ? -1 : 0;
}
static thread_semaphore_t *Thread_CreateSemaphore(unsigned int v)
{
- thread_semaphore_t *s = (thread_semaphore_t *)calloc(sizeof(*s), 1);
+ thread_semaphore_t *s = (thread_semaphore_t *)malloc(sizeof(thread_semaphore_t));
s->semaphore = CreateSemaphore(NULL, v, 32768, NULL);
s->value = v;
return s;
}
thread_cond_t;
-void *_Thread_CreateCond(const char *filename, int fileline)
+void *Thread_CreateCond(void)
{
- thread_cond_t *c = (thread_cond_t *)calloc(sizeof(*c), 1);
+ thread_cond_t *c = (thread_cond_t *)malloc(sizeof(thread_cond_t));
c->mutex = CreateMutex(NULL, FALSE, NULL);
c->sem = Thread_CreateSemaphore(0);
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, const char *filename, int fileline)
+void Thread_DestroyCond(void *cond)
{
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);
+ free(c); // Izy's Patch
}
-int _Thread_CondSignal(void *cond, const char *filename, int fileline)
+int Thread_CondSignal(void *cond)
{
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)
return 0;
}
-int _Thread_CondBroadcast(void *cond, const char *filename, int fileline)
+int Thread_CondBroadcast(void *cond)
{
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)
return 0;
}
-int _Thread_CondWait(void *cond, void *mutex, const char *filename, int fileline)
+int Thread_CondWait(void *cond, void *mutex)
{
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++;
return w->result;
}
-void *_Thread_CreateThread(int (*fn)(void *), void *data, const char *filename, int fileline)
+void *Thread_CreateThread(int (*fn)(void *), void *data)
{
- threadwrapper_t *w = (threadwrapper_t *)calloc(sizeof(*w), 1);
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p thread create %s:%i\n" , w, filename, fileline);
-#endif
+ threadwrapper_t *w = (threadwrapper_t *)malloc(sizeof(threadwrapper_t));
w->fn = fn;
w->data = data;
w->threadid = 0;
return (void *)w;
}
-int _Thread_WaitThread(void *d, int retval, const char *filename, int fileline)
+void Thread_WaitThread(void *d, int *retval)
{
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;
+ if(retval)
+ *retval = w->result;
free(w);
- return retval;
}
// standard barrier implementation using conds and mutexes
void *cond;
} barrier_t;
-void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+void *Thread_CreateBarrier(unsigned int count)
{
- volatile barrier_t *b = (volatile barrier_t *) Z_Malloc(sizeof(barrier_t));
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
-#endif
+ volatile barrier_t *b = (volatile barrier_t *) malloc(sizeof(barrier_t));
b->needed = count;
b->called = 0;
b->mutex = Thread_CreateMutex();
return (void *) b;
}
-void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+void Thread_DestroyBarrier(void *barrier)
{
volatile barrier_t *b = (volatile barrier_t *) barrier;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier destroy %s:%i\n", b, filename, fileline);
-#endif
Thread_DestroyMutex(b->mutex);
Thread_DestroyCond(b->cond);
+ free((void*)b); // Izy's Patch
}
-void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+void Thread_WaitBarrier(void *barrier)
{
volatile barrier_t *b = (volatile barrier_t *) barrier;
-#ifdef THREADDEBUG
- Sys_PrintfToTerminal("%p barrier wait %s:%i\n", b, filename, fileline);
-#endif
Thread_LockMutex(b->mutex);
b->called++;
if (b->called == b->needed) {
}
Thread_UnlockMutex(b->mutex);
}
+
+
+void Thread_SetThreadPriorityLow(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_LOWEST);
+}
+
+void Thread_SetThreadPriorityNormal(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
+}
+
+void Thread_SetThreadPriorityHigh(void)
+{
+ /* Thread Priority added by Izy (izy from http://www.izysoftware.com/) */
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
+}