28 #include <sys/types.h>
39 #include "../../idlib/precompiled.h"
63 #ifdef ID_VERBOSE_PTHREADS
64 if ( pthread_mutex_trylock( &global_lock[index] ) == EBUSY ) {
66 if ( pthread_mutex_lock( &global_lock[index] ) == EDEADLK ) {
71 pthread_mutex_lock( &global_lock[index] );
82 #ifdef ID_VERBOSE_PTHREADS
83 if ( pthread_mutex_unlock( &global_lock[index] ) == EPERM ) {
87 pthread_mutex_unlock( &global_lock[index] );
152 #define MAX_THREADS 10
157 typedef void *(*pthread_function_t) (
void *);
167 pthread_attr_init( &attr );
168 if ( pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ) != 0 ) {
169 common->
Error(
"ERROR: pthread_attr_setdetachstate %s failed\n", name );
172 common->
Error(
"ERROR: pthread_create %s failed\n", name );
174 pthread_attr_destroy( &attr );
177 threads[ ( *thread_count )++ ] = &info;
192 if ( pthread_cancel( ( pthread_t )info.
threadHandle ) != 0 ) {
201 if ( &info == g_threads[
i ] ) {
202 g_threads[
i ] =
NULL;
205 g_threads[ j-1 ] = g_threads[
j ];
207 g_threads[ j-1 ] =
NULL;
224 pthread_t thread = pthread_self();
226 if ( thread == (pthread_t)g_threads[
i ]->threadHandle ) {
231 return g_threads[
i ]->
name;
270 pthread_mutexattr_t attr;
274 pthread_mutexattr_init( &attr );
275 pthread_mutexattr_settype( &attr, PTHREAD_MUTEX_ERRORCHECK );
276 pthread_mutex_init( &global_lock[i], &attr );
277 pthread_mutexattr_destroy( &attr );
289 g_threads[
i ] =
NULL;
void Sys_AsyncThread(void)
pthread_cond_t event_cond[MAX_TRIGGER_EVENTS]
assert(prefInfo.fullscreenBtn)
void Posix_InitPThreads()
bool signaled[MAX_TRIGGER_EVENTS]
void Sys_Printf(const char *msg,...)
const int MAX_LOCAL_CRITICAL_SECTIONS
const int MAX_CRITICAL_SECTIONS
const int MAX_TRIGGER_EVENTS
void Sys_DestroyThread(xthreadInfo &info)
xthreadInfo * g_threads[MAX_THREADS]
unsigned int(* xthread_t)(void *)
const char * Sys_GetThreadName(int *index)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
bool waiting[MAX_TRIGGER_EVENTS]
void Sys_TriggerEvent(int index)
void Posix_StartAsyncThread()
void *(* pthread_function_t)(void *)
virtual void DPrintf(const char *fmt,...) id_attribute((format(printf
virtual void Error(const char *fmt,...) id_attribute((format(printf
void Sys_LeaveCriticalSection(int index)
void Sys_EnterCriticalSection(int index)
void Sys_WaitForEvent(int index)
void Sys_CreateThread(xthread_t function, void *parms, xthreadPriority priority, xthreadInfo &info, const char *name, xthreadInfo **threads, int *thread_count)