KeReleaseSemaphore & KeReadStateSemaphore

When I call KeReleaseSemaphore() are the results
of KeReadStateSemaphore() immediately changed, or
do I have to wait until any waiting threads are
run by the scheduler.

The reason I ask is that I have an unknown number
of threads waiting on my semaphore. When I’m
doing a cleanup, I set a flag that prevents anymore
threads from entering the wait, and I want to release
all threads currently waiting. What I want to write
is code like this:

// Release all waiters…
while ( KeReadStateSemaphore(&pDevExt->semaphore) == 0 )
{
// Increment the semaphore count by one; if this satisfies
// a wait, it will be atomically decremented back to zero
// and the semaphore will still not be signaled when this
// function returns. If there are no waiters, the semaphore
// will be signaled when this function returns.
KeReleaseSemaphore(&pDevExt->semaphore,
0,
1,
FALSE);
}

Is the comment correct? Will this code work? Is there a better
way to achieve the desired result?

Thanks,

Joseph