Added timeout to critical section waiting.

This commit is contained in:
Alexandre Julliard 1999-04-18 13:23:36 +00:00
parent a44f9f8e1b
commit 79762059eb
1 changed files with 10 additions and 2 deletions

View File

@ -53,6 +53,8 @@ void WINAPI DeleteCriticalSection( CRITICAL_SECTION *crit )
*/ */
void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit ) void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit )
{ {
DWORD res;
if (!crit->LockSemaphore) if (!crit->LockSemaphore)
{ {
FIXME(win32,"entering uninitialized section(%p)?\n",crit); FIXME(win32,"entering uninitialized section(%p)?\n",crit);
@ -66,8 +68,14 @@ void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit )
return; return;
} }
/* Now wait for it */ /* Now wait for it */
/* FIXME: should set a timeout and raise an exception */
WaitForSingleObject( crit->LockSemaphore, INFINITE ); res = WaitForSingleObject( crit->LockSemaphore, 2000 );
if (res == STATUS_TIMEOUT) res = WaitForSingleObject( crit->LockSemaphore, 2000 );
if (res != STATUS_WAIT_0)
{
ERR(win32, "Critical section %p wait failed err=%lx\n", crit, res );
/* FIXME: should raise an exception */
}
} }
crit->OwningThread = GetCurrentThreadId(); crit->OwningThread = GetCurrentThreadId();
crit->RecursionCount = 1; crit->RecursionCount = 1;