From d7acbe2251aa76fb6d7623aa70eb3dcbcb7fbc27 Mon Sep 17 00:00:00 2001 From: jean Date: Wed, 31 Mar 1999 13:38:13 +0000 Subject: [PATCH] correct bug in release of semaphore svn path=/trunk/; revision=356 --- reactos/ntoskrnl/ke/sem.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/reactos/ntoskrnl/ke/sem.c b/reactos/ntoskrnl/ke/sem.c index d2f78e9b807..5728e4b38e1 100644 --- a/reactos/ntoskrnl/ke/sem.c +++ b/reactos/ntoskrnl/ke/sem.c @@ -24,7 +24,7 @@ VOID KeInitializeSemaphore(PKSEMAPHORE Semaphore, KeInitializeDispatcherHeader(&Semaphore->Header,SemaphoreType, sizeof(KSEMAPHORE)/sizeof(ULONG), Count); - Semaphore->Limit = Limit; + Semaphore->Limit=Limit; } LONG KeReadStateSemaphore(PKSEMAPHORE Semaphore) @@ -37,26 +37,18 @@ LONG KeReleaseSemaphore(PKSEMAPHORE Semaphore, LONG Adjustment, BOOLEAN Wait) { - ULONG initState = Semaphore->Header.SignalState; - - KeAcquireDispatcherDatabaseLock(Wait); - - if(Semaphore->Limit < initState+Adjustment + ULONG initState = Semaphore->Header.SignalState; + KeAcquireDispatcherDatabaseLock(Wait); + if(Semaphore->Limit < initState+Adjustment || initState > initState+Adjustment) - { - ExRaiseStatus(STATUS_SEMAPHORE_LIMIT_EXCEEDED); - } - - Semaphore->Header.SignalState += Adjustment; - if (initState == 0) - { - // wake up SignalState waiters - while(Semaphore->Header.SignalState > 0 - && KeDispatcherObjectWake(&Semaphore->Header)) ; - } - - KeReleaseDispatcherDatabaseLock(Wait); - - return initState; + ExRaiseStatus(STATUS_SEMAPHORE_LIMIT_EXCEEDED); + Semaphore->Header.SignalState+=Adjustment; + if(initState == 0) + { + // wake up SignalState waiters + KeDispatcherObjectWake(&Semaphore->Header) ; + } + KeReleaseDispatcherDatabaseLock(Wait); + return initState; }