From b9815e86e026c431050253146177f5c624a28756 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Sat, 5 Aug 2017 03:38:38 +0200 Subject: [PATCH] ntdll: Add inline versions of RtlEnterCriticalSection / RtlLeaveCriticalSections. --- dlls/ntdll/ntdll_misc.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 67696f80db3..f25d8adc217 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -26,6 +26,7 @@ #include "winnt.h" #include "winternl.h" #include "unixlib.h" +#include "wine/debug.h" #include "wine/asm.h" #define DECLARE_CRITICAL_SECTION(cs) \ @@ -96,6 +97,39 @@ extern int ntdll_wcstoumbs( const WCHAR* src, DWORD srclen, char* dst, DWORD dst extern int CDECL NTDLL__vsnprintf( char *str, SIZE_T len, const char *format, __ms_va_list args ) DECLSPEC_HIDDEN; extern int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, __ms_va_list args ) DECLSPEC_HIDDEN; +/* inline version of RtlEnterCriticalSection */ +static inline void enter_critical_section( RTL_CRITICAL_SECTION *crit ) +{ + if (InterlockedIncrement( &crit->LockCount )) + { + if (crit->OwningThread == ULongToHandle(GetCurrentThreadId())) + { + crit->RecursionCount++; + return; + } + RtlpWaitForCriticalSection( crit ); + } + crit->OwningThread = ULongToHandle(GetCurrentThreadId()); + crit->RecursionCount = 1; +} + +/* inline version of RtlLeaveCriticalSection */ +static inline void leave_critical_section( RTL_CRITICAL_SECTION *crit ) +{ + WINE_DECLARE_DEBUG_CHANNEL(ntdll); + if (--crit->RecursionCount) + { + if (crit->RecursionCount > 0) InterlockedDecrement( &crit->LockCount ); + else ERR_(ntdll)( "section %p is not acquired\n", crit ); + } + else + { + crit->OwningThread = 0; + if (InterlockedDecrement( &crit->LockCount ) >= 0) + RtlpUnWaitCriticalSection( crit ); + } +} + /* load order */ enum loadorder -- 2.30.0