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
27 void Threads_Glue_Yield(void)
32 void Threads_Glue_AcquireMutex(void **Lock)
35 *Lock = malloc( sizeof(pthread_mutex_t) );
36 pthread_mutex_init( *Lock, NULL );
38 pthread_mutex_lock( *Lock );
41 void Threads_Glue_ReleaseMutex(void **Lock)
43 pthread_mutex_unlock( *Lock );
46 void Threads_Glue_SemInit(void **Ptr, int Val)
48 *Ptr = SDL_CreateSemaphore(Val);
50 Log_Warning("Threads", "Semaphore creation failed - %s", SDL_GetError());
54 int Threads_Glue_SemWait(void *Ptr, int Max)
59 if( SDL_SemWait( Ptr ) == -1 ) {
63 } while( SDL_SemValue(Ptr) && have < Max );
67 int Threads_Glue_SemSignal( void *Ptr, int AmmountToAdd )
69 for( int i = 0; i < AmmountToAdd; i ++ )
74 void Threads_Glue_SemDestroy( void *Ptr )
76 SDL_DestroySemaphore(Ptr);
82 void Threads_int_ShortLock(void **MutexPtr)
85 *MutexPtr = malloc( sizeof(pthread_mutex_t) );
86 pthread_mutexattr_t attr;
87 pthread_mutexattr_init(&attr);
88 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
89 pthread_mutex_init(*MutexPtr, NULL);
91 if( pthread_mutex_lock(*MutexPtr) ) {
92 fprintf(stderr, "ERROR: Mutex pointer %p double locked\n", MutexPtr);
97 void Threads_int_ShortRel(void **MutexPtr)
99 pthread_mutex_unlock(*MutexPtr);
102 int Threads_int_ShortHas(void **Ptr)
106 int rv = pthread_mutex_trylock(*Ptr);
108 pthread_mutex_unlock(*Ptr);