Commit 2745228b authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

ntdll: Don't use debug info presence to detect critical section global status.

parent e1606d69
...@@ -163,29 +163,16 @@ static const char *crit_section_get_name( const RTL_CRITICAL_SECTION *crit ) ...@@ -163,29 +163,16 @@ static const char *crit_section_get_name( const RTL_CRITICAL_SECTION *crit )
static inline HANDLE get_semaphore( RTL_CRITICAL_SECTION *crit ) static inline HANDLE get_semaphore( RTL_CRITICAL_SECTION *crit )
{ {
HANDLE ret = crit->LockSemaphore; if ((ULONG_PTR)crit->LockSemaphore > 1) return crit->LockSemaphore;
if (!ret) return NULL;
{
HANDLE sem;
if (NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 )) return 0;
if (!(ret = InterlockedCompareExchangePointer( &crit->LockSemaphore, sem, 0 )))
ret = sem;
else
NtClose(sem); /* somebody beat us to it */
}
return ret;
} }
static inline NTSTATUS wait_semaphore( RTL_CRITICAL_SECTION *crit, int timeout ) static inline NTSTATUS wait_semaphore( RTL_CRITICAL_SECTION *crit, int timeout )
{ {
LARGE_INTEGER time = {.QuadPart = timeout * (LONGLONG)-10000000}; LARGE_INTEGER time = {.QuadPart = timeout * (LONGLONG)-10000000};
HANDLE sem = get_semaphore( crit );
/* debug info is cleared by MakeCriticalSectionGlobal */ if (sem) return NtWaitForSingleObject( sem, FALSE, &time );
if (!crit_section_has_debuginfo( crit ))
{
HANDLE sem = get_semaphore( crit );
return NtWaitForSingleObject( sem, FALSE, &time );
}
else else
{ {
LONG *lock = (LONG *)&crit->LockSemaphore; LONG *lock = (LONG *)&crit->LockSemaphore;
...@@ -276,6 +263,8 @@ ULONG WINAPI RtlSetCriticalSectionSpinCount( RTL_CRITICAL_SECTION *crit, ULONG s ...@@ -276,6 +263,8 @@ ULONG WINAPI RtlSetCriticalSectionSpinCount( RTL_CRITICAL_SECTION *crit, ULONG s
*/ */
NTSTATUS WINAPI RtlDeleteCriticalSection( RTL_CRITICAL_SECTION *crit ) NTSTATUS WINAPI RtlDeleteCriticalSection( RTL_CRITICAL_SECTION *crit )
{ {
HANDLE sem;
crit->LockCount = -1; crit->LockCount = -1;
crit->RecursionCount = 0; crit->RecursionCount = 0;
crit->OwningThread = 0; crit->OwningThread = 0;
...@@ -288,11 +277,9 @@ NTSTATUS WINAPI RtlDeleteCriticalSection( RTL_CRITICAL_SECTION *crit ) ...@@ -288,11 +277,9 @@ NTSTATUS WINAPI RtlDeleteCriticalSection( RTL_CRITICAL_SECTION *crit )
crit->DebugInfo = NULL; crit->DebugInfo = NULL;
} }
} }
else else crit->DebugInfo = NULL;
{
NtClose( crit->LockSemaphore ); if ((sem = get_semaphore( crit ))) NtClose( sem );
crit->DebugInfo = NULL;
}
crit->LockSemaphore = 0; crit->LockSemaphore = 0;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -335,13 +322,9 @@ NTSTATUS WINAPI RtlpWaitForCriticalSection( RTL_CRITICAL_SECTION *crit ) ...@@ -335,13 +322,9 @@ NTSTATUS WINAPI RtlpWaitForCriticalSection( RTL_CRITICAL_SECTION *crit )
NTSTATUS WINAPI RtlpUnWaitCriticalSection( RTL_CRITICAL_SECTION *crit ) NTSTATUS WINAPI RtlpUnWaitCriticalSection( RTL_CRITICAL_SECTION *crit )
{ {
NTSTATUS ret; NTSTATUS ret;
HANDLE sem = get_semaphore( crit );
/* debug info is cleared by MakeCriticalSectionGlobal */ if (sem) ret = NtReleaseSemaphore( sem, 1, NULL );
if (!crit_section_has_debuginfo( crit ))
{
HANDLE sem = get_semaphore( crit );
ret = NtReleaseSemaphore( sem, 1, NULL );
}
else else
{ {
LONG *lock = (LONG *)&crit->LockSemaphore; LONG *lock = (LONG *)&crit->LockSemaphore;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment