From: John Hodge Date: Sat, 14 Jul 2012 09:49:06 +0000 (+0800) Subject: Kernel/rwlock - Fixed wrong logic causing lockup X-Git-Tag: rel0.15~611^2~39 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3734719792d583e82208729b7142133745f12095;p=tpg%2Facess2.git Kernel/rwlock - Fixed wrong logic causing lockup --- diff --git a/KernelLand/Kernel/rwlock.c b/KernelLand/Kernel/rwlock.c index 6706bb22..979df4ac 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 @@ -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(); @@ -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