X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fsemaphore.c;h=e8175741d07089b77c4418f08e37067f4882961a;hb=82595a34a73b4667a98349cceeb17f618bd41282;hp=ce7d4ba05f4ef40f37583a47ec5c310658c39fe1;hpb=2db551c69841b4fb5a70ae05e08d54b1a016364b;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/semaphore.c b/KernelLand/Kernel/semaphore.c index ce7d4ba0..e8175741 100644 --- a/KernelLand/Kernel/semaphore.c +++ b/KernelLand/Kernel/semaphore.c @@ -50,6 +50,11 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake) } else { + #if 0 + Threads_int_Sleep(THREAD_STAT_SEMAPHORESLEEP, + Sem, MaxToTake, + &Sem->Waiting, &Sem->LastWaiting, &Sem->Protector); + #endif SHORTLOCK( &glThreadListLock ); // - Remove from active list @@ -75,21 +80,15 @@ int Semaphore_Wait(tSemaphore *Sem, int MaxToTake) us, us->TID, us->ThreadName, Sem, Sem->ModName, Sem->Name); #endif - - SHORTREL( &Sem->Protector ); // Release first to make sure it is released + SHORTREL( &Sem->Protector ); SHORTREL( &glThreadListLock ); + // NOTE: This can break in SMP // Sleep until woken (either by getting what we need, or a timer event) - 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); - } + Threads_int_WaitForStatusEnd( THREAD_STAT_SEMAPHORESLEEP ); + // We're only woken when there's something avaliable (or a signal arrives) #if DEBUG_TRACE_STATE || SEMAPHORE_DEBUG - Log("Semaphore %p %s:%s woken", Sem, Sem->ModName, Sem->Name); + Log("Semaphore %p %s:%s woken from wait", Sem, Sem->ModName, Sem->Name); #endif - // We're only woken when there's something avaliable (or a signal arrives) us->WaitPointer = NULL; taken = us->RetStatus; @@ -191,7 +190,7 @@ int Semaphore_Signal(tSemaphore *Sem, int AmmountToAdd) SHORTREL( &glThreadListLock ); SHORTREL( &Sem->Protector ); - while(us->Status == THREAD_STAT_SEMAPHORESLEEP) Threads_Yield(); + Threads_int_WaitForStatusEnd(THREAD_STAT_SEMAPHORESLEEP); // We're only woken when there's something avaliable us->WaitPointer = NULL;