2 * Acess2 libnative (Kernel Simulation Library)
3 * - By John Hodge (thePowersGang)
10 #include <threads_int.h>
13 int gbThreads_MultithreadingEnabled;
14 tThread __thread *lpThreads_This;
17 tThread *Proc_GetCurThread(void)
19 return lpThreads_This;
22 void Threads_PostEvent(tThread *Thread, Uint32 Events)
24 Threads_int_LockMutex(Thread->Protector);
25 Thread->PendingEvents |= Events;
26 if( Thread->WaitingEvents & Events )
27 Threads_int_SemaphoreSignal(Thread->WaitSemaphore);
28 Threads_int_ReleaseMutex(Thread->Protector);
31 Uint32 Threads_WaitEvents(Uint32 Events)
33 Thread->WaitingEvents = Events;
34 Threads_int_SemaphoreWaitAll(Thread->WaitSemaphore);
35 Thread->WaitingEvents = 0;
36 Uint32 rv = Thread->PendingEvents;
40 void Threads_ClearEvent(Uint32 Mask)
42 Threads_int_LockMutex(Thread->Protector);
43 lpThreads_This->PendingEvents &= ~Mask;
44 Threads_int_ReleaseMutex(Thread->Protector);
47 tUID Threads_GetUID(void) { return 0; }
48 tGID Threads_GetGID(void) { return 0; }
50 tTID Threads_GetTID(void) { return 0; }
52 int *Threads_GetMaxFD(void) { static int max_fd=32; return &max_fd; }
53 char **Threads_GetCWD(void) { static char *cwd; return &cwd; }
54 char **Threads_GetChroot(void) { static char *chroot; return &chroot; }
56 void Threads_Yield(void)
58 Log_Warning("Threads", "Threads_Yield DEFINITELY shouldn't be used");
61 void Threads_Sleep(void)
63 Log_Warning("Threads", "Threads_Sleep shouldn't be used");
66 int Threads_SetName(const char *Name)
68 Log_Notice("Threads", "TODO: Threads_SetName('%s')", Name);
72 int *Threads_GetErrno(void) __attribute__ ((weak));
74 int *Threads_GetErrno(void)// __attribute__ ((weak))
80 struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data)
82 if( !gbThreads_MultithreadingEnabled )
84 Log_Error("Threads", "Multithreading is disabled in this build");
89 tThread *ret = malloc( sizeof(tThread) );
91 ret->SpawnData = Data;
92 Threads_int_CreateThread(ret);
93 Log_Error("Threads", "TODO - Use pthreads to impliment Proc_SpawnWorker");