3 * - Acess kernel emulation on another OS using SDL and UDP
6 * - Thread and process handling
8 #include "include/threads_glue.h"
11 typedef void **tShortSpinlock;
16 #include <sys/types.h>
18 //#include "/usr/include/signal.h"
22 #define NORETURN __attribute__((noreturn))
24 #include <logdebug.h> // Kernel land, but uses standards
28 void Threads_Glue_Yield(void)
33 void Threads_Glue_AcquireMutex(void **Lock)
36 *Lock = malloc( sizeof(pthread_mutex_t) );
37 pthread_mutex_init( *Lock, NULL );
39 pthread_mutex_lock( *Lock );
42 void Threads_Glue_ReleaseMutex(void **Lock)
44 pthread_mutex_unlock( *Lock );
47 void Threads_Glue_SemInit(void **Ptr, int Val)
49 *Ptr = SDL_CreateSemaphore(Val);
51 Log_Warning("Threads", "Semaphore creation failed - %s", SDL_GetError());
55 int Threads_Glue_SemWait(void *Ptr, int Max)
60 if( SDL_SemWait( Ptr ) == -1 ) {
64 } while( SDL_SemValue(Ptr) && have < Max );
68 int Threads_Glue_SemSignal( void *Ptr, int AmmountToAdd )
70 for( int i = 0; i < AmmountToAdd; i ++ )
75 void Threads_Glue_SemDestroy( void *Ptr )
77 SDL_DestroySemaphore(Ptr);
83 void Threads_int_ShortLock(void **MutexPtr)
86 *MutexPtr = malloc( sizeof(pthread_mutex_t) );
87 pthread_mutexattr_t attr;
88 pthread_mutexattr_init(&attr);
89 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
90 pthread_mutex_init(*MutexPtr, NULL);
92 if( pthread_mutex_lock(*MutexPtr) ) {
93 fprintf(stderr, "ERROR: Mutex pointer %p double locked\n", MutexPtr);
98 void Threads_int_ShortRel(void **MutexPtr)
100 pthread_mutex_unlock(*MutexPtr);
103 int Threads_int_ShortHas(void **Ptr)
107 int rv = pthread_mutex_trylock(*Ptr);
109 pthread_mutex_unlock(*Ptr);