+ pthread_mutex_lock( (void*)Mutex );
+ }
+ else
+ {
+ if( Mutex->lock )
+ Log_KernelPanic("Threads", "Double mutex lock");
+ Mutex->lock = 1;
+ }
+}
+
+void Threads_int_MutexRelease(tThreadIntMutex *Mutex)
+{
+ if( !Mutex ) {
+ return ;
+ }
+
+ if( pthread_mutex_unlock )
+ {
+ pthread_mutex_unlock( (void*)Mutex );
+ }
+ else
+ {
+ if( !Mutex->lock )
+ Log_Notice("Threads", "Release of non-locked mutex %p", Mutex);
+ Mutex->lock = 0;
+ }
+}
+
+void Threads_int_SemSignal(tThreadIntSem *Sem)
+{
+ if( sem_wait )
+ {
+ sem_wait( (void*)Sem );
+ }
+ else
+ {
+ Sem->val ++;
+ }
+}
+
+void Threads_int_SemWaitAll(tThreadIntSem *Sem)
+{
+ if( sem_post )
+ {
+ sem_post( (void*)Sem );
+ }
+ else
+ {
+ if( !Sem->val )
+ Log_KernelPanic("Threads", "Waiting on empty semaphre %p", Sem);
+ Sem->val = 0;
+ }
+}
+
+void *Threads_int_ThreadRoot(void *ThreadPtr)
+{
+ tThread *thread = ThreadPtr;
+ thread->SpawnFcn(thread->SpawnData);
+ return NULL;
+}
+
+int Threads_int_CreateThread(tThread *Thread)
+{
+ if( pthread_create )
+ {
+ pthread_t *pthread = malloc(sizeof(pthread_t));
+ Thread->ThreadHandle = pthread;
+ return pthread_create(pthread, NULL, Threads_int_ThreadRoot, Thread);