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 #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 )
69 for( i = 0; i < AmmountToAdd; i ++ )
74 // --------------------------------------------------------------------
76 // --------------------------------------------------------------------
77 int RWLock_AcquireRead(tRWLock *Lock)
79 if( !Lock->ReaderWaiting ) {
80 Lock->ReaderWaiting = malloc(sizeof(pthread_rwlock_t));
81 pthread_rwlock_init( (void*)Lock->ReaderWaiting, 0 );
83 pthread_rwlock_rdlock( (void*)Lock->ReaderWaiting );
86 int RWLock_AcquireWrite(tRWLock *Lock)
88 if( !Lock->ReaderWaiting ) {
89 Lock->ReaderWaiting = malloc(sizeof(pthread_rwlock_t));
90 pthread_rwlock_init( (void*)Lock->ReaderWaiting, 0 );
92 pthread_rwlock_wrlock( (void*)Lock->ReaderWaiting );
95 void RWLock_Release(tRWLock *Lock)
97 pthread_rwlock_unlock( (void*)Lock->ReaderWaiting );