[RTL] Do not mess with critical section lock when there is no reason to.

- When process is shutting down.
 - When the caller is so drunk that they leave twice the pub altough they entered it only once.
This commit is contained in:
Jérôme Gardou 2021-01-29 18:15:17 +01:00
parent 6d697561f0
commit 2486558ae1

View file

@ -114,12 +114,6 @@ RtlpWaitForCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
EXCEPTION_RECORD ExceptionRecord; EXCEPTION_RECORD ExceptionRecord;
BOOLEAN LastChance = FALSE; BOOLEAN LastChance = FALSE;
/* Do we have an Event yet? */
if (!CriticalSection->LockSemaphore)
{
RtlpCreateCriticalSectionSem(CriticalSection);
}
/* Increase the Debug Entry count */ /* Increase the Debug Entry count */
DPRINT("Waiting on Critical Section Event: %p %p\n", DPRINT("Waiting on Critical Section Event: %p %p\n",
CriticalSection, CriticalSection,
@ -136,10 +130,15 @@ RtlpWaitForCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
LdrpShutdownThreadId == NtCurrentTeb()->RealClientId.UniqueThread) LdrpShutdownThreadId == NtCurrentTeb()->RealClientId.UniqueThread)
{ {
DPRINT("Forcing ownership of critical section %p\n", CriticalSection); DPRINT("Forcing ownership of critical section %p\n", CriticalSection);
CriticalSection->LockCount = 0;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
/* Do we have an Event yet? */
if (!CriticalSection->LockSemaphore)
{
RtlpCreateCriticalSectionSem(CriticalSection);
}
for (;;) for (;;)
{ {
/* Increase the number of times we've had contention */ /* Increase the number of times we've had contention */
@ -715,9 +714,13 @@ RtlLeaveCriticalSection(PRTL_CRITICAL_SECTION CriticalSection)
*/ */
if (--CriticalSection->RecursionCount) if (--CriticalSection->RecursionCount)
{ {
if (CriticalSection->RecursionCount < 0)
{
DPRINT1("CRITICAL SECTION MESS: Section %p is not acquired!\n", CriticalSection);
return STATUS_UNSUCCESSFUL;
}
/* Someone still owns us, but we are free. This needs to be done atomically. */ /* Someone still owns us, but we are free. This needs to be done atomically. */
InterlockedDecrement(&CriticalSection->LockCount); InterlockedDecrement(&CriticalSection->LockCount);
} }
else else
{ {