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"
23 #define NORETURN __attribute__((noreturn))
24 #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 )
70 for( i = 0; i < AmmountToAdd; i ++ )
75 // --------------------------------------------------------------------
77 // --------------------------------------------------------------------
78 int RWLock_AcquireRead(tRWLock *Lock)
80 if( !Lock->ReaderWaiting ) {
81 Lock->ReaderWaiting = malloc(sizeof(pthread_rwlock_t));
82 pthread_rwlock_init( (void*)Lock->ReaderWaiting, 0 );
84 pthread_rwlock_rdlock( (void*)Lock->ReaderWaiting );
87 int RWLock_AcquireWrite(tRWLock *Lock)
89 if( !Lock->ReaderWaiting ) {
90 Lock->ReaderWaiting = malloc(sizeof(pthread_rwlock_t));
91 pthread_rwlock_init( (void*)Lock->ReaderWaiting, 0 );
93 pthread_rwlock_wrlock( (void*)Lock->ReaderWaiting );
96 void RWLock_Release(tRWLock *Lock)
98 pthread_rwlock_unlock( (void*)Lock->ReaderWaiting );