If you just want to check if a semaphore wait would block, then just call the wait function with timeout 0:
extern HANDLE warnEventHandle;
extern HANDLE mySemaphore;
bool waitForSemaphore( DWORD timeout )
{
if(WAIT_TIMEOUT == WaitForSingleObject(mySemaphore, 0))
{
SetEvent(warnEventHandle);
return (WAIT_OBJECT_O == WaitForSingleObject(mySemaphore, timeout));
}
return true;
}
EDIT: Changed the example a bit. The first version would aquire the semaphore twice. Still, this code is only an illustration - the return value from WaitForSingleObject should be checked properly on each call.