Alexandre Julliard : ntdll: Use a pthread mutex for the wait on address section.

Alexandre Julliard julliard at winehq.org
Mon Jul 13 16:08:50 CDT 2020


Module: wine
Branch: master
Commit: 052e8dbf5985ffa5875067491b03a523257752f9
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=052e8dbf5985ffa5875067491b03a523257752f9

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Jul 13 18:48:21 2020 +0200

ntdll: Use a pthread mutex for the wait on address section.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/unix/server.c       |  8 ++++----
 dlls/ntdll/unix/sync.c         | 25 +++++++++----------------
 dlls/ntdll/unix/unix_private.h |  2 +-
 3 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c
index 9a593f7725..faca7da5c9 100644
--- a/dlls/ntdll/unix/server.c
+++ b/dlls/ntdll/unix/server.c
@@ -590,7 +590,7 @@ static void invoke_system_apc( const apc_call_t *call, apc_result_t *result )
  *              server_select
  */
 unsigned int server_select( const select_op_t *select_op, data_size_t size, UINT flags,
-                            timeout_t abs_timeout, CONTEXT *context, RTL_CRITICAL_SECTION *cs,
+                            timeout_t abs_timeout, CONTEXT *context, pthread_mutex_t *mutex,
                             user_apc_t *user_apc )
 {
     unsigned int ret;
@@ -649,10 +649,10 @@ unsigned int server_select( const select_op_t *select_op, data_size_t size, UINT
                 size = offsetof( select_op_t, signal_and_wait.signal );
         }
         pthread_sigmask( SIG_SETMASK, &old_set, NULL );
-        if (cs)
+        if (mutex)
         {
-            RtlLeaveCriticalSection( cs );
-            cs = NULL;
+            pthread_mutex_unlock( mutex );
+            mutex = NULL;
         }
         if (ret != STATUS_PENDING) break;
 
diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c
index 5080caef52..69263efa0e 100644
--- a/dlls/ntdll/unix/sync.c
+++ b/dlls/ntdll/unix/sync.c
@@ -78,15 +78,7 @@ HANDLE keyed_event = 0;
 
 static const LARGE_INTEGER zero_timeout;
 
-static RTL_CRITICAL_SECTION addr_section;
-static RTL_CRITICAL_SECTION_DEBUG addr_section_debug =
-{
-    0, 0, &addr_section,
-    { &addr_section_debug.ProcessLocksList, &addr_section_debug.ProcessLocksList },
-      0, 0, { (DWORD_PTR)(__FILE__ ": addr_section") }
-};
-static RTL_CRITICAL_SECTION addr_section = { &addr_section_debug, -1, 0, 0, 0, 0 };
-
+static pthread_mutex_t addr_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 /* return a monotonic time counter, in Win32 ticks */
 static inline ULONGLONG monotonic_counter(void)
@@ -2253,10 +2245,10 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size
     if ((ret = fast_wait_addr( addr, cmp, size, timeout )) != STATUS_NOT_IMPLEMENTED)
         return ret;
 
-    RtlEnterCriticalSection( &addr_section );
+    pthread_mutex_lock( &addr_mutex );
     if (!compare_addr( addr, cmp, size ))
     {
-        RtlLeaveCriticalSection( &addr_section );
+        pthread_mutex_unlock( &addr_mutex );
         return STATUS_SUCCESS;
     }
 
@@ -2272,7 +2264,8 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size
     select_op.keyed_event.handle = wine_server_obj_handle( keyed_event );
     select_op.keyed_event.key    = wine_server_client_ptr( addr );
 
-    return server_select( &select_op, sizeof(select_op.keyed_event), SELECT_INTERRUPTIBLE, abs_timeout, NULL, &addr_section, NULL );
+    return server_select( &select_op, sizeof(select_op.keyed_event), SELECT_INTERRUPTIBLE,
+                          abs_timeout, NULL, &addr_mutex, NULL );
 }
 
 /***********************************************************************
@@ -2282,9 +2275,9 @@ void WINAPI RtlWakeAddressAll( const void *addr )
 {
     if (fast_wake_addr( addr ) != STATUS_NOT_IMPLEMENTED) return;
 
-    RtlEnterCriticalSection( &addr_section );
+    pthread_mutex_lock( &addr_mutex );
     while (NtReleaseKeyedEvent( 0, addr, 0, &zero_timeout ) == STATUS_SUCCESS) {}
-    RtlLeaveCriticalSection( &addr_section );
+    pthread_mutex_unlock( &addr_mutex );
 }
 
 /***********************************************************************
@@ -2294,7 +2287,7 @@ void WINAPI RtlWakeAddressSingle( const void *addr )
 {
     if (fast_wake_addr( addr ) != STATUS_NOT_IMPLEMENTED) return;
 
-    RtlEnterCriticalSection( &addr_section );
+    pthread_mutex_lock( &addr_mutex );
     NtReleaseKeyedEvent( 0, addr, 0, &zero_timeout );
-    RtlLeaveCriticalSection( &addr_section );
+    pthread_mutex_unlock( &addr_mutex );
 }
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index 2a73f17e10..3d56ea5d40 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -162,7 +162,7 @@ extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN;
 extern void server_enter_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset ) DECLSPEC_HIDDEN;
 extern void server_leave_uninterrupted_section( pthread_mutex_t *mutex, sigset_t *sigset ) DECLSPEC_HIDDEN;
 extern unsigned int server_select( const select_op_t *select_op, data_size_t size, UINT flags,
-                                   timeout_t abs_timeout, CONTEXT *context, RTL_CRITICAL_SECTION *cs,
+                                   timeout_t abs_timeout, CONTEXT *context, pthread_mutex_t *mutex,
                                    user_apc_t *user_apc ) DECLSPEC_HIDDEN;
 extern unsigned int server_wait( const select_op_t *select_op, data_size_t size, UINT flags,
                                  const LARGE_INTEGER *timeout ) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list