X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Frwlock.c;h=a6aeca885e977bd76fd2708c32b3dede4c73e97a;hb=17ebf0cdf584b5eb63aa96149de3e4f76cb82e01;hp=6706bb228f66f1ce03940c621b0ed3fd72d67c71;hpb=11dbd684e9a3d907d43d71a3145205f1a86992fb;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/rwlock.c b/KernelLand/Kernel/rwlock.c index 6706bb22..a6aeca88 100644 --- a/KernelLand/Kernel/rwlock.c +++ b/KernelLand/Kernel/rwlock.c @@ -5,6 +5,7 @@ * rwlock.c * - Reader-Writer Lockes */ +#define DEBUG 0 #include #include #include @@ -16,12 +17,14 @@ 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 ) { + LOG("Waiting"); SHORTLOCK( &glThreadListLock ); // - Remove from active list @@ -45,7 +48,7 @@ int RWLock_AcquireRead(tRWLock *Lock) SHORTREL( &glThreadListLock ); SHORTREL( &Lock->Protector ); - while(us->Status == THREAD_STAT_RWLOCKSLEEP) Threads_Yield(); + 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; @@ -56,6 +59,7 @@ int RWLock_AcquireRead(tRWLock *Lock) Lock->Level++; SHORTREL( & Lock->Protector ); } + LOG("Obtained"); return 0; } @@ -64,9 +68,12 @@ 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(); @@ -83,7 +90,7 @@ int RWLock_AcquireWrite(tRWLock *Lock) SHORTREL( &glThreadListLock ); SHORTREL( &Lock->Protector ); - while(us->Status == THREAD_STAT_RWLOCKSLEEP) Threads_Yield(); + Threads_int_WaitForStatusEnd(THREAD_STAT_RWLOCKSLEEP); us->WaitPointer = NULL; } else @@ -92,15 +99,17 @@ int RWLock_AcquireWrite(tRWLock *Lock) Lock->Owner = Proc_GetCurThread(); SHORTREL(&Lock->Protector); } + LOG("Obtained"); return 0; } // Release a mutex void RWLock_Release(tRWLock *Lock) { + LOG("Release RWLock %p", Lock); SHORTLOCK( &Lock->Protector ); - if( Lock->Owner == Proc_GetCurThread() ) + if( Lock->Owner != Proc_GetCurThread() ) Lock->Level --; // Writers first