2 * Acess2 libnative (Kernel Simulation Library)
3 * - By John Hodge (thePowersGang)
10 #include <threads_int.h>
13 tThread __thread *lpThreads_This;
16 tThread *Proc_GetCurThread(void)
18 return lpThreads_This;
21 void Threads_PostEvent(tThread *Thread, Uint32 Events)
27 Threads_int_MutexLock(Thread->Protector);
28 Thread->PendingEvents |= Events;
29 if( Thread->WaitingEvents & Events )
30 Threads_int_SemSignal(Thread->WaitSemaphore);
31 Threads_int_MutexRelease(Thread->Protector);
34 Uint32 Threads_WaitEvents(Uint32 Events)
36 if( !lpThreads_This ) {
37 Log_Notice("Threads", "_WaitEvents: Threading disabled");
40 lpThreads_This->WaitingEvents = Events;
41 Threads_int_SemWaitAll(lpThreads_This->WaitSemaphore);
42 lpThreads_This->WaitingEvents = 0;
43 Uint32 rv = lpThreads_This->PendingEvents;
47 void Threads_ClearEvent(Uint32 Mask)
49 if( !lpThreads_This ) {
50 Log_Notice("Threads", "_ClearEvent: Threading disabled");
53 Threads_int_MutexLock(lpThreads_This->Protector);
54 lpThreads_This->PendingEvents &= ~Mask;
55 Threads_int_MutexRelease(lpThreads_This->Protector);
58 tUID Threads_GetUID(void) { return 0; }
59 tGID Threads_GetGID(void) { return 0; }
61 tTID Threads_GetTID(void) { return 0; }
63 int *Threads_GetMaxFD(void) { static int max_fd=32; return &max_fd; }
64 char **Threads_GetCWD(void) { static char *cwd; return &cwd; }
65 char **Threads_GetChroot(void) { static char *chroot; return &chroot; }
67 void Threads_Yield(void)
69 Log_Warning("Threads", "Threads_Yield DEFINITELY shouldn't be used");
72 void Threads_Sleep(void)
74 Log_Warning("Threads", "Threads_Sleep shouldn't be used");
77 int Threads_SetName(const char *Name)
79 Log_Notice("Threads", "TODO: Threads_SetName('%s')", Name);
83 int *Threads_GetErrno(void) __attribute__ ((weak));
85 int *Threads_GetErrno(void)// __attribute__ ((weak))
91 struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data)
95 Log_Error("Threads", "Multithreading is disabled in this build");
100 tThread *ret = malloc( sizeof(tThread) );
102 ret->SpawnData = Data;
103 Threads_int_CreateThread(ret);