X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fthreads.c;h=2f8d933179d5a557dd79ced9f44f0177fd844ced;hb=066ea7cb8cd5c873734405d0b713cb330c79ed49;hp=949f6d23e6d9d00c3b8e97e3d7a7deae8a41b9a6;hpb=86e230f582b2d342a0ae487bf8028f782a099a1d;p=tpg%2Facess2.git diff --git a/Kernel/threads.c b/Kernel/threads.c index 949f6d23..2f8d9331 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -14,7 +14,7 @@ // Configuration #define DEBUG_TRACE_TICKETS 0 // Trace ticket counts #define DEBUG_TRACE_STATE 0 // Trace state changes (sleep/wake) -#define SEMAPHORE_DEBUG 0 +#define SEMAPHORE_DEBUG 0 // Debug semaphores // --- Schedulers --- #define SCHED_UNDEF 0 @@ -618,7 +618,7 @@ void Threads_Kill(tThread *Thread, int Status) } break; - // Brains!... You cannot kill + // Brains!... You cannot kill something that is already dead case THREAD_STAT_ZOMBIE: Log_Warning("Threads", "Threads_Kill - Thread %p(%i,%s) is undead, you cannot kill it", Thread, Thread->TID, Thread->ThreadName); @@ -635,6 +635,8 @@ void Threads_Kill(tThread *Thread, int Status) // Save exit status Thread->RetStatus = Status; + SHORTREL( &Thread->IsLocked ); + // Don't Zombie if we are being killed because our parent is if(Status == -1) { @@ -650,9 +652,6 @@ void Threads_Kill(tThread *Thread, int Status) Log("Thread %i went *hurk* (%i)", Thread->TID, Status); - // Release spinlocks - SHORTREL( &Thread->IsLocked ); // TODO: We may not actually be released... - // And, reschedule if(isCurThread) { @@ -713,7 +712,6 @@ void Threads_Sleep(void) /** - * \fn int Threads_Wake( tThread *Thread ) * \brief Wakes a sleeping/waiting thread up * \param Thread Thread to wake * \return Boolean Failure (Returns ERRNO) @@ -783,6 +781,7 @@ int Threads_Wake(tThread *Thread) sem->LastSignaling = prev; } + Thread->RetStatus = 0; // It didn't get anything Threads_AddActive( Thread ); #if DEBUG_TRACE_STATE @@ -1509,8 +1508,17 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake) #endif SHORTREL( &Sem->Protector ); // Release first to make sure it is released - SHORTREL( &glThreadListLock ); - while(us->Status == THREAD_STAT_SEMAPHORESLEEP) Threads_Yield(); + SHORTREL( &glThreadListLock ); + while( us->Status == THREAD_STAT_SEMAPHORESLEEP ) + { + Threads_Yield(); + if(us->Status == THREAD_STAT_SEMAPHORESLEEP) + Log_Warning("Threads", "Semaphore %p %s:%s re-schedulued while asleep", + Sem, Sem->ModName, Sem->Name); + } + #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG + Log("Semaphore %p %s:%s woken", Sem, Sem->ModName, Sem->Name); + #endif // We're only woken when there's something avaliable (or a signal arrives) us->WaitPointer = NULL; @@ -1557,6 +1565,11 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake) } SHORTREL( &Sem->Protector ); + #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG + Log("Semaphore %p %s:%s took %i by wait", + Sem, Sem->ModName, Sem->Name, taken); + #endif + return taken; } @@ -1661,12 +1674,12 @@ int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd) #endif // Wake the sleeper - SHORTLOCK( &glThreadListLock ); +// SHORTLOCK( &glThreadListLock ); if( toWake->Status != THREAD_STAT_ACTIVE ) Threads_AddActive(toWake); else Warning("Thread %p (%i %s) is already awake", toWake, toWake->TID, toWake->ThreadName); - SHORTREL( &glThreadListLock ); +// SHORTREL( &glThreadListLock ); } SHORTREL( &Sem->Protector );