nativelib - Compile fixes
[tpg/acess2.git] / Tools / nativelib / threads.c
index 5055dc3..eafe87f 100644 (file)
@@ -7,27 +7,52 @@
  */
 #include <acess.h>
 #include <threads.h>
+#include <threads_int.h>
+
+// === GLOBALS ===
+tThread __thread       *lpThreads_This;
 
 // === CODE ===
 tThread *Proc_GetCurThread(void)
 {
-       return NULL;
+       return lpThreads_This;
 }
 
 void Threads_PostEvent(tThread *Thread, Uint32 Events)
 {
-       
+       if( !Thread ) {
+               // nope.avi
+               return ;
+       }
+       Threads_int_MutexLock(Thread->Protector);
+       Thread->PendingEvents |= Events;
+       if( Thread->WaitingEvents & Events )
+               Threads_int_SemSignal(Thread->WaitSemaphore);
+       Threads_int_MutexRelease(Thread->Protector);
 }
 
 Uint32 Threads_WaitEvents(Uint32 Events)
 {
-       Log_KernelPanic("Threads", "Can't use _WaitEvents in DiskTool");
-       return 0;
+       if( !lpThreads_This ) {
+               Log_Notice("Threads", "_WaitEvents: Threading disabled");
+               return 0;
+       }
+       lpThreads_This->WaitingEvents = Events;
+       Threads_int_SemWaitAll(lpThreads_This->WaitSemaphore);
+       lpThreads_This->WaitingEvents = 0;
+       Uint32  rv = lpThreads_This->PendingEvents;
+       return rv;
 }
 
 void Threads_ClearEvent(Uint32 Mask)
 {
-       
+       if( !lpThreads_This ) {
+               Log_Notice("Threads", "_ClearEvent: Threading disabled");
+               return ;
+       }
+       Threads_int_MutexLock(lpThreads_This->Protector);
+       lpThreads_This->PendingEvents &= ~Mask;
+       Threads_int_MutexRelease(lpThreads_This->Protector);
 }
 
 tUID Threads_GetUID(void) { return 0; }
@@ -63,3 +88,20 @@ int *Threads_GetErrno(void)// __attribute__ ((weak))
        return &a_errno;
 }
 
+struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data)
+{
+       if( !lpThreads_This )
+       {
+               Log_Error("Threads", "Multithreading is disabled in this build");
+               return NULL;
+       }
+       else
+       {
+               tThread *ret = malloc( sizeof(tThread) );
+               ret->SpawnFcn = Fcn;
+               ret->SpawnData = Data;
+               Threads_int_CreateThread(ret);
+               return ret;
+       }
+}
+

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