X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Frwlock.c;h=1fd64592325ee191dd2f54eb69a1ba792d121306;hb=d7dcea0e5a8df0f479e99f168a10b9a9535c7ad6;hp=a6aeca885e977bd76fd2708c32b3dede4c73e97a;hpb=6b29d7427e7d1ad73f0a0d0ae771bd25da7b7f1a;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/rwlock.c b/KernelLand/Kernel/rwlock.c index a6aeca88..1fd64592 100644 --- a/KernelLand/Kernel/rwlock.c +++ b/KernelLand/Kernel/rwlock.c @@ -16,42 +16,18 @@ // int RWLock_AcquireRead(tRWLock *Lock) { - tThread *us; LOG("Acquire RWLock Read %p", Lock); // Get protector SHORTLOCK( &Lock->Protector ); // Check if the lock is already held by a writer - if( Lock->Owner ) + // - OR, there's a writer waiting to write + if( Lock->Owner || Lock->WriterWaiting ) { LOG("Waiting"); - SHORTLOCK( &glThreadListLock ); - - // - Remove from active list - us = Threads_RemActive(); - us->Next = NULL; - // - Mark as sleeping - us->Status = THREAD_STAT_RWLOCKSLEEP; - us->WaitPointer = Lock; - - // - Add to waiting - if(Lock->ReaderWaiting) - Lock->ReaderWaitingLast->Next = us; - else - Lock->ReaderWaiting = us; - Lock->ReaderWaitingLast = us; - - #if DEBUG_TRACE_STATE - Log("%p (%i %s) waiting on rwlock %p", - us, us->TID, us->ThreadName, Lock); - #endif - - SHORTREL( &glThreadListLock ); - SHORTREL( &Lock->Protector ); - Threads_int_WaitForStatusEnd(THREAD_STAT_RWLOCKSLEEP); - // We're only woken when we get the lock - // TODO: Handle when this isn't the case - us->WaitPointer = NULL; + Threads_int_Sleep(THREAD_STAT_RWLOCKSLEEP, Lock, 0, + &Lock->ReaderWaiting, &Lock->ReaderWaitingLast, + &Lock->Protector); } // Ooh, no problems then! else @@ -66,32 +42,15 @@ int RWLock_AcquireRead(tRWLock *Lock) int RWLock_AcquireWrite(tRWLock *Lock) { - tThread *us; - LOG("Acquire RWLock Write %p", Lock); SHORTLOCK(&Lock->Protector); if( Lock->Owner || Lock->Level != 0 ) { LOG("Waiting"); - SHORTLOCK(&glThreadListLock); - - us = Threads_RemActive(); - us->Next = NULL; - us->Status = THREAD_STAT_RWLOCKSLEEP; - us->WaitPointer = Lock; - - if( Lock->WriterWaiting ) - Lock->WriterWaitingLast->Next = us; - else - Lock->WriterWaiting = us; - Lock->WriterWaitingLast = us; - - SHORTREL( &glThreadListLock ); - SHORTREL( &Lock->Protector ); - - Threads_int_WaitForStatusEnd(THREAD_STAT_RWLOCKSLEEP); - us->WaitPointer = NULL; + Threads_int_Sleep(THREAD_STAT_RWLOCKSLEEP, Lock, 0, + &Lock->WriterWaiting, &Lock->WriterWaitingLast, + &Lock->Protector); } else {