fixed RtlEnterCriticalSection not to fail on wrong assumptions and added comment on why the debug message "Critical section not initialized (guess)" is wrong

svn path=/trunk/; revision=13641
This commit is contained in:
Thomas Bluemel 2005-02-19 13:13:17 +00:00
parent 99f3640c17
commit c6a8c7496f

View file

@ -144,23 +144,27 @@ RtlEnterCriticalSection(
*/ */
if (Thread == CriticalSection->OwningThread) { if (Thread == CriticalSection->OwningThread) {
/* You own it, so you'll get it when you're done with it! */ /* You own it, so you'll get it when you're done with it! No need to
use the interlocked functions as only the thread who already owns
the lock can modify this data. */
CriticalSection->RecursionCount++; CriticalSection->RecursionCount++;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
else if (CriticalSection->OwningThread == (HANDLE)0)
{ /* NOTE - CriticalSection->OwningThread can be NULL here because changing
/* No one else owns it either! */ this information is not serialized. This happens when thread a
DPRINT1("Critical section not initialized (guess)!\n"); acquires the lock (LockCount == 0) and thread b tries to
/* FIXME: raise exception */ acquire it as well (LockCount == 1) but thread a hasn't had a
return STATUS_INVALID_PARAMETER; chance to set the OwningThread! So it's not an error when
} OwningThread is NULL here! */
/* We don't own it, so we must wait for it */ /* We don't own it, so we must wait for it */
RtlpWaitForCriticalSection(CriticalSection); RtlpWaitForCriticalSection(CriticalSection);
} }
/* Lock successful */ /* Lock successful. Changing this information has not to be serialized because
only one thread at a time can actually change it (the one who acquired
the lock)! */
CriticalSection->OwningThread = Thread; CriticalSection->OwningThread = Thread;
CriticalSection->RecursionCount = 1; CriticalSection->RecursionCount = 1;
return STATUS_SUCCESS; return STATUS_SUCCESS;