2 * Acess2 libnative (Kernel Simulation Library)
3 * - By John Hodge (thePowersGang)
6 * - Internal threading functions
11 #include <acess_logging.h>
12 #include <threads_int.h>
13 #include <pthread_weak.h>
16 typedef struct sThread tThread;
17 struct sThreadIntMutex { int lock; };
18 struct sThreadIntSem { int val; };
21 void Threads_int_MutexLock(tThreadIntMutex *Mutex)
26 if( pthread_mutex_lock )
28 pthread_mutex_lock( (void*)Mutex );
33 Log_KernelPanic("Threads", "Double mutex lock");
38 void Threads_int_MutexRelease(tThreadIntMutex *Mutex)
44 if( pthread_mutex_unlock )
46 pthread_mutex_unlock( (void*)Mutex );
51 Log_Notice("Threads", "Release of non-locked mutex %p", Mutex);
56 void Threads_int_SemSignal(tThreadIntSem *Sem)
60 sem_wait( (void*)Sem );
68 void Threads_int_SemWaitAll(tThreadIntSem *Sem)
72 sem_post( (void*)Sem );
77 Log_KernelPanic("Threads", "Waiting on empty semaphre %p", Sem);
82 void *Threads_int_ThreadRoot(void *ThreadPtr)
84 tThread *thread = ThreadPtr;
85 thread->SpawnFcn(thread->SpawnData);
89 int Threads_int_CreateThread(tThread *Thread)
93 pthread_t *pthread = malloc(sizeof(pthread_t));
94 Thread->ThreadHandle = pthread;
95 return pthread_create(pthread, NULL, Threads_int_ThreadRoot, Thread);
99 Log_KernelPanic("Threads", "Link with pthreads to use threading");