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))
23 #include <logdebug.h> // Kernel land, but uses standards
26 void Threads_Glue_Yield(void)
31 void Threads_Glue_AcquireMutex(void **Lock)
34 *Lock = malloc( sizeof(pthread_mutex_t) );
35 pthread_mutex_init( *Lock, NULL );
37 pthread_mutex_lock( *Lock );
40 void Threads_Glue_ReleaseMutex(void **Lock)
42 pthread_mutex_unlock( *Lock );
45 void Threads_Glue_SemInit(void **Ptr, int Val)
47 *Ptr = SDL_CreateSemaphore(Val);
49 Log_Warning("Threads", "Semaphore creation failed - %s", SDL_GetError());
53 int Threads_Glue_SemWait(void *Ptr, int Max)
58 if( SDL_SemWait( Ptr ) == -1 ) {
62 } while( SDL_SemValue(Ptr) && have < Max );
66 int Threads_Glue_SemSignal( void *Ptr, int AmmountToAdd )
68 for( int i = 0; i < AmmountToAdd; i ++ )
73 void Threads_Glue_SemDestroy( void *Ptr )
75 SDL_DestroySemaphore(Ptr);
81 void Threads_int_ShortLock(void **MutexPtr)
84 *MutexPtr = malloc( sizeof(pthread_mutex_t) );
85 pthread_mutex_init(*MutexPtr, NULL);
87 pthread_mutex_lock(*MutexPtr);
90 void Threads_int_ShortRel(void **MutexPtr)
92 pthread_mutex_unlock(*MutexPtr);