Overloaded Loop
by in CodeSOD on 2017-01-30Brian found himself digging through some C++ code, trying to figure out a cross-thread synchronization bug. It had something to do with the NetLockWait
function, based on his debugging, so he dug into the code.
bool CMyDatastore::NetLockWait(DWORD dwEvent, long nRecord, CMySignal& Signal, DWORD dwTieout)
{
bool retBool;
long value;
DWORD reason;
DWORD currentAttach;
CTimerElapsed timeout;
timeout.SetTime(dwTimeout);
retBool = false;
while (timeout)
{
if (::WaitForSingleObject(Signal.GetEvent(), timeout) != WAIT_OBJECT_0)
{
break;
}
ReserveSynch();
Signal.Pop(reason, value);
ReleaseSynch();
if (reason == dwEvent && value == nRecord)
{
retBool = true;
break;
}
}
return (retBool);
}