wine-staging/patches/ntdll-CriticalSection/0002-ntdll-Add-inline-versions-of-RtlEnterCriticalSection.patch
2023-11-16 11:07:12 +11:00

66 lines
2.0 KiB
Diff

From 4dd82c635bcf8c2c7d070d6c5786787ff2d7d887 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
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 a7967a6c242..8b088f9d3c3 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -28,6 +28,7 @@
#include "winnt.h"
#include "winternl.h"
#include "unixlib.h"
+#include "wine/debug.h"
#include "wine/asm.h"
#define DECLARE_CRITICAL_SECTION(cs) \
@@ -94,6 +95,39 @@ extern struct _KUSER_SHARED_DATA *user_shared_data;
extern int CDECL NTDLL__vsnprintf( char *str, SIZE_T len, const char *format, va_list args );
extern int CDECL NTDLL__vsnwprintf( WCHAR *str, SIZE_T len, const WCHAR *format, va_list args );
+/* 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 );
+ }
+}
+
struct dllredirect_data
{
ULONG size;
--
2.42.0