correct bug in release of semaphore

svn path=/trunk/; revision=356
This commit is contained in:
jean 1999-03-31 13:38:13 +00:00
parent 3763d9c0dd
commit d7acbe2251

View file

@ -24,7 +24,7 @@ VOID KeInitializeSemaphore(PKSEMAPHORE Semaphore,
KeInitializeDispatcherHeader(&Semaphore->Header,SemaphoreType, KeInitializeDispatcherHeader(&Semaphore->Header,SemaphoreType,
sizeof(KSEMAPHORE)/sizeof(ULONG), sizeof(KSEMAPHORE)/sizeof(ULONG),
Count); Count);
Semaphore->Limit = Limit; Semaphore->Limit=Limit;
} }
LONG KeReadStateSemaphore(PKSEMAPHORE Semaphore) LONG KeReadStateSemaphore(PKSEMAPHORE Semaphore)
@ -37,26 +37,18 @@ LONG KeReleaseSemaphore(PKSEMAPHORE Semaphore,
LONG Adjustment, LONG Adjustment,
BOOLEAN Wait) BOOLEAN Wait)
{ {
ULONG initState = Semaphore->Header.SignalState; ULONG initState = Semaphore->Header.SignalState;
KeAcquireDispatcherDatabaseLock(Wait);
KeAcquireDispatcherDatabaseLock(Wait); if(Semaphore->Limit < initState+Adjustment
if(Semaphore->Limit < initState+Adjustment
|| initState > initState+Adjustment) || initState > initState+Adjustment)
{ ExRaiseStatus(STATUS_SEMAPHORE_LIMIT_EXCEEDED);
ExRaiseStatus(STATUS_SEMAPHORE_LIMIT_EXCEEDED); Semaphore->Header.SignalState+=Adjustment;
} if(initState == 0)
{
Semaphore->Header.SignalState += Adjustment; // wake up SignalState waiters
if (initState == 0) KeDispatcherObjectWake(&Semaphore->Header) ;
{ }
// wake up SignalState waiters KeReleaseDispatcherDatabaseLock(Wait);
while(Semaphore->Header.SignalState > 0 return initState;
&& KeDispatcherObjectWake(&Semaphore->Header)) ;
}
KeReleaseDispatcherDatabaseLock(Wait);
return initState;
} }