Tools/nativelib - Many features implimented
[tpg/acess2.git] / Tools / nativelib / threads_int.c
index 2274eea..f25ab95 100644 (file)
@@ -17,7 +17,29 @@ typedef struct sThread       tThread;
 struct sThreadIntMutex { int lock; };
 struct sThreadIntSem { int val; };
 
+// === PROTOTYPES ===
+
 // === CODE ===
+int Threads_int_ThreadingEnabled(void)
+{
+       Log_Debug("Threads", "pthread_create = %p", pthread_create);
+       return !!pthread_create;
+}
+
+tThreadIntMutex *Threads_int_MutexCreate(void)
+{
+       if( pthread_mutex_init )
+       {
+               tThreadIntMutex *ret = malloc(sizeof(pthread_mutex_t));
+               pthread_mutex_init( (void*)ret, NULL );
+               return ret;
+       }
+       else
+       {
+               return calloc(sizeof(tThreadIntMutex), 1);
+       }
+}
+
 void Threads_int_MutexLock(tThreadIntMutex *Mutex)
 {
        if( !Mutex ) {
@@ -53,6 +75,20 @@ void Threads_int_MutexRelease(tThreadIntMutex *Mutex)
        }
 }
 
+tThreadIntSem *Threads_int_SemCreate(void)
+{
+       if( sem_init )
+       {
+               tThreadIntSem *ret = malloc(sizeof(sem_t));
+               sem_init( (void*)ret, 0, 0 );
+               return ret;
+       }
+       else
+       {
+               return calloc(sizeof(tThreadIntSem), 1);
+       }
+}
+
 void Threads_int_SemSignal(tThreadIntSem *Sem)
 {
        if( sem_wait )
@@ -82,6 +118,8 @@ void Threads_int_SemWaitAll(tThreadIntSem *Sem)
 void *Threads_int_ThreadRoot(void *ThreadPtr)
 {
        tThread *thread = ThreadPtr;
+       lpThreads_This = thread;
+       Log_Debug("Threads", "SpawnFcn: %p, SpawnData: %p", thread->SpawnFcn, thread->SpawnData);
        thread->SpawnFcn(thread->SpawnData);
        return NULL;
 }
@@ -92,7 +130,7 @@ int Threads_int_CreateThread(tThread *Thread)
        {
                pthread_t *pthread = malloc(sizeof(pthread_t));
                Thread->ThreadHandle = pthread;
-               return pthread_create(pthread, NULL, Threads_int_ThreadRoot, Thread);
+               return pthread_create(pthread, NULL, &Threads_int_ThreadRoot, Thread);
        }
        else
        {

UCC git Repository :: git.ucc.asn.au