X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fmutex.c;h=a869df5342089b0966924b43d99a797b4f8da861;hb=3c283c4831c40c14d308a54cefb997832a860bca;hp=d74cde8f185dc62b55ca15c2cefecf53ea8f320c;hpb=6b29d7427e7d1ad73f0a0d0ae771bd25da7b7f1a;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/mutex.c b/KernelLand/Kernel/mutex.c index d74cde8f..a869df53 100644 --- a/KernelLand/Kernel/mutex.c +++ b/KernelLand/Kernel/mutex.c @@ -31,47 +31,14 @@ int Mutex_Acquire(tMutex *Mutex) // Check if the lock is already held if( Mutex->Owner ) { - SHORTLOCK( &glThreadListLock ); - // - Remove from active list - us = Threads_RemActive(); - us->Next = NULL; - // - Mark as sleeping - us->Status = THREAD_STAT_MUTEXSLEEP; - us->WaitPointer = Mutex; - - // - Add to waiting - if(Mutex->LastWaiting) { - Mutex->LastWaiting->Next = us; - Mutex->LastWaiting = us; - } - else { - Mutex->Waiting = us; - Mutex->LastWaiting = us; - } - - #if DEBUG_TRACE_STATE - Log("%p (%i %s) waiting on mutex %p", - us, us->TID, us->ThreadName, Mutex); - #endif - - #if 0 - { - int i = 0; - tThread *t; - for( t = Mutex->Waiting; t; t = t->Next, i++ ) - Log("[%i] (tMutex)%p->Waiting[%i] = %p (%i %s)", us->TID, Mutex, i, - t, t->TID, t->ThreadName); - } - #endif - - SHORTREL( &glThreadListLock ); - SHORTREL( &Mutex->Protector ); - Threads_int_WaitForStatusEnd(THREAD_STAT_MUTEXSLEEP); - // We're only woken when we get the lock - us->WaitPointer = NULL; + // Sleep on the lock + Threads_int_Sleep(THREAD_STAT_MUTEXSLEEP, + Mutex, 0, + &Mutex->Waiting, &Mutex->LastWaiting, &Mutex->Protector); + // - We're only woken when we get the lock } - // Ooh, let's take it! else { + // If not, just obtain it Mutex->Owner = us; SHORTREL( &Mutex->Protector ); }