*/
#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; }
struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data)
{
- Log_Error("Threads", "TODO - Use pthreads to impliment Proc_SpawnWorker");
- return NULL;
+ 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;
+ }
}