X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fthreads.c;h=dc4d643aae75b169b491a42b57b72225cf35f4fe;hb=4ad6151eb6d3138c9070cb376f5ba9fa3ec511e8;hp=3465992630f9491a9af8deb594103a15dec60132;hpb=717454930aa0e255517c68c837927deac49bd78e;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/threads.c b/AcessNative/acesskernel_src/threads.c index 34659926..dc4d643a 100644 --- a/AcessNative/acesskernel_src/threads.c +++ b/AcessNative/acesskernel_src/threads.c @@ -70,8 +70,8 @@ typedef struct sThread // === GLOBALS === tThread gThreadZero = { - State: 1, - ThreadName: "ThreadZero" + .State=1, + .ThreadName="ThreadZero" }; tThread *gpThreads = &gThreadZero; __thread tThread *gpCurrentThread = &gThreadZero; @@ -207,6 +207,7 @@ int Threads_WaitTID(int TID, int *Status) us->Next = NULL; us->State = 3; + // TODO: Locking if(thread->WaitingThreadsEnd) { thread->WaitingThreadsEnd->Next = us; @@ -219,7 +220,10 @@ int Threads_WaitTID(int TID, int *Status) } while(thread->State != 0) + { pause(); + Log_Debug("Threads", "Huh?... state = %i", thread->State); + } if(Status) *Status = thread->ExitStatus; thread->WaitingThreads = thread->WaitingThreads->Next; @@ -247,15 +251,22 @@ void Threads_Exit(int TID, int Status) tThread *toWake; // VFS_Handles_Cleanup(); + + gpCurrentThread->ExitStatus = Status; #if 1 - // Wait for the thread to be waited upon - while( gpCurrentThread->WaitingThreads == NULL ) - SDL_Delay(10); + if( gpCurrentThread->Parent ) + { + // Wait for the thread to be waited upon + while( gpCurrentThread->WaitingThreads == NULL ) + SDL_Delay(10); + } #endif while( (toWake = gpCurrentThread->WaitingThreads) ) { + Log_Debug("Threads", "Threads_Exit - Waking %p %i '%s'", toWake, toWake->TID, toWake->ThreadName); + Threads_Wake(toWake); while(gpCurrentThread->WaitingThreads == toWake) @@ -265,6 +276,7 @@ void Threads_Exit(int TID, int Status) int Threads_Wake(tThread *Thread) { + Thread->State = 0; kill( Thread->KernelTID, SIGUSR1 ); return 0; }