Alexandre Julliard : ntdll: Use the default keyed event when the handle is null.

Alexandre Julliard julliard at winehq.org
Fri Oct 26 14:23:56 CDT 2018


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Oct 26 11:27:11 2018 +0200

ntdll: Use the default keyed event when the handle is null.

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

---

 dlls/ntdll/sync.c     | 36 +++++++++++++++++++-----------------
 dlls/ntdll/tests/om.c |  4 ++--
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c
index 1bfaaab..a00a159 100644
--- a/dlls/ntdll/sync.c
+++ b/dlls/ntdll/sync.c
@@ -1189,6 +1189,7 @@ NTSTATUS WINAPI NtWaitForKeyedEvent( HANDLE handle, const void *key,
     select_op_t select_op;
     UINT flags = SELECT_INTERRUPTIBLE;
 
+    if (!handle) handle = keyed_event;
     if ((ULONG_PTR)key & 1) return STATUS_INVALID_PARAMETER_1;
     if (alertable) flags |= SELECT_ALERTABLE;
     select_op.keyed_event.op     = SELECT_KEYED_EVENT_WAIT;
@@ -1206,6 +1207,7 @@ NTSTATUS WINAPI NtReleaseKeyedEvent( HANDLE handle, const void *key,
     select_op_t select_op;
     UINT flags = SELECT_INTERRUPTIBLE;
 
+    if (!handle) handle = keyed_event;
     if ((ULONG_PTR)key & 1) return STATUS_INVALID_PARAMETER_1;
     if (alertable) flags |= SELECT_ALERTABLE;
     select_op.keyed_event.op     = SELECT_KEYED_EVENT_RELEASE;
@@ -1524,7 +1526,7 @@ DWORD WINAPI RtlRunOnceBeginInitialize( RTL_RUN_ONCE *once, ULONG flags, void **
             next = val & ~3;
             if (interlocked_cmpxchg_ptr( &once->Ptr, (void *)((ULONG_PTR)&next | 1),
                                          (void *)val ) == (void *)val)
-                NtWaitForKeyedEvent( keyed_event, &next, FALSE, NULL );
+                NtWaitForKeyedEvent( 0, &next, FALSE, NULL );
             break;
 
         case 2:  /* done */
@@ -1564,7 +1566,7 @@ DWORD WINAPI RtlRunOnceComplete( RTL_RUN_ONCE *once, ULONG flags, void *context
             while (val)
             {
                 ULONG_PTR next = *(ULONG_PTR *)val;
-                NtReleaseKeyedEvent( keyed_event, (void *)val, FALSE, NULL );
+                NtReleaseKeyedEvent( 0, (void *)val, FALSE, NULL );
                 val = next;
             }
             return STATUS_SUCCESS;
@@ -1704,12 +1706,12 @@ static inline void srwlock_leave_exclusive( RTL_SRWLOCK *lock, unsigned int val
      * exclusive access threads they are processed first, followed by
      * the shared waiters. */
     if (val & SRWLOCK_MASK_EXCLUSIVE_QUEUE)
-        NtReleaseKeyedEvent( keyed_event, srwlock_key_exclusive(lock), FALSE, NULL );
+        NtReleaseKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
     else
     {
         val &= SRWLOCK_MASK_SHARED_QUEUE; /* remove SRWLOCK_MASK_IN_EXCLUSIVE */
         while (val--)
-            NtReleaseKeyedEvent( keyed_event, srwlock_key_shared(lock), FALSE, NULL );
+            NtReleaseKeyedEvent( 0, srwlock_key_shared(lock), FALSE, NULL );
     }
 }
 
@@ -1718,7 +1720,7 @@ static inline void srwlock_leave_shared( RTL_SRWLOCK *lock, unsigned int val )
     /* Wake up one exclusive thread as soon as the last shared access thread
      * has left. */
     if ((val & SRWLOCK_MASK_EXCLUSIVE_QUEUE) && !(val & SRWLOCK_MASK_SHARED_QUEUE))
-        NtReleaseKeyedEvent( keyed_event, srwlock_key_exclusive(lock), FALSE, NULL );
+        NtReleaseKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
 }
 
 /***********************************************************************
@@ -1747,7 +1749,7 @@ void WINAPI RtlInitializeSRWLock( RTL_SRWLOCK *lock )
 void WINAPI RtlAcquireSRWLockExclusive( RTL_SRWLOCK *lock )
 {
     if (srwlock_lock_exclusive( (unsigned int *)&lock->Ptr, SRWLOCK_RES_EXCLUSIVE ))
-        NtWaitForKeyedEvent( keyed_event, srwlock_key_exclusive(lock), FALSE, NULL );
+        NtWaitForKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
 }
 
 /***********************************************************************
@@ -1775,14 +1777,14 @@ void WINAPI RtlAcquireSRWLockShared( RTL_SRWLOCK *lock )
     /* Drop exclusive access again and instead requeue for shared access. */
     if ((val & SRWLOCK_MASK_EXCLUSIVE_QUEUE) && !(val & SRWLOCK_MASK_IN_EXCLUSIVE))
     {
-        NtWaitForKeyedEvent( keyed_event, srwlock_key_exclusive(lock), FALSE, NULL );
+        NtWaitForKeyedEvent( 0, srwlock_key_exclusive(lock), FALSE, NULL );
         val = srwlock_unlock_exclusive( (unsigned int *)&lock->Ptr, (SRWLOCK_RES_SHARED
                                         - SRWLOCK_RES_EXCLUSIVE) ) - SRWLOCK_RES_EXCLUSIVE;
         srwlock_leave_exclusive( lock, val );
     }
 
     if (val & SRWLOCK_MASK_EXCLUSIVE_QUEUE)
-        NtWaitForKeyedEvent( keyed_event, srwlock_key_shared(lock), FALSE, NULL );
+        NtWaitForKeyedEvent( 0, srwlock_key_shared(lock), FALSE, NULL );
 }
 
 /***********************************************************************
@@ -1866,7 +1868,7 @@ void WINAPI RtlInitializeConditionVariable( RTL_CONDITION_VARIABLE *variable )
 void WINAPI RtlWakeConditionVariable( RTL_CONDITION_VARIABLE *variable )
 {
     if (interlocked_dec_if_nonzero( (int *)&variable->Ptr ))
-        NtReleaseKeyedEvent( keyed_event, &variable->Ptr, FALSE, NULL );
+        NtReleaseKeyedEvent( 0, &variable->Ptr, FALSE, NULL );
 }
 
 /***********************************************************************
@@ -1878,7 +1880,7 @@ void WINAPI RtlWakeAllConditionVariable( RTL_CONDITION_VARIABLE *variable )
 {
     int val = interlocked_xchg( (int *)&variable->Ptr, 0 );
     while (val-- > 0)
-        NtReleaseKeyedEvent( keyed_event, &variable->Ptr, FALSE, NULL );
+        NtReleaseKeyedEvent( 0, &variable->Ptr, FALSE, NULL );
 }
 
 /***********************************************************************
@@ -1903,11 +1905,11 @@ NTSTATUS WINAPI RtlSleepConditionVariableCS( RTL_CONDITION_VARIABLE *variable, R
     interlocked_xchg_add( (int *)&variable->Ptr, 1 );
     RtlLeaveCriticalSection( crit );
 
-    status = NtWaitForKeyedEvent( keyed_event, &variable->Ptr, FALSE, timeout );
+    status = NtWaitForKeyedEvent( 0, &variable->Ptr, FALSE, timeout );
     if (status != STATUS_SUCCESS)
     {
         if (!interlocked_dec_if_nonzero( (int *)&variable->Ptr ))
-            status = NtWaitForKeyedEvent( keyed_event, &variable->Ptr, FALSE, NULL );
+            status = NtWaitForKeyedEvent( 0, &variable->Ptr, FALSE, NULL );
     }
 
     RtlEnterCriticalSection( crit );
@@ -1944,11 +1946,11 @@ NTSTATUS WINAPI RtlSleepConditionVariableSRW( RTL_CONDITION_VARIABLE *variable,
     else
         RtlReleaseSRWLockExclusive( lock );
 
-    status = NtWaitForKeyedEvent( keyed_event, &variable->Ptr, FALSE, timeout );
+    status = NtWaitForKeyedEvent( 0, &variable->Ptr, FALSE, timeout );
     if (status != STATUS_SUCCESS)
     {
         if (!interlocked_dec_if_nonzero( (int *)&variable->Ptr ))
-            status = NtWaitForKeyedEvent( keyed_event, &variable->Ptr, FALSE, NULL );
+            status = NtWaitForKeyedEvent( 0, &variable->Ptr, FALSE, NULL );
     }
 
     if (flags & RTL_CONDITION_VARIABLE_LOCKMODE_SHARED)
@@ -1986,7 +1988,7 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size
             return STATUS_INVALID_PARAMETER;
     }
 
-    return NtWaitForKeyedEvent( keyed_event, addr, 0, timeout );
+    return NtWaitForKeyedEvent( 0, addr, 0, timeout );
 }
 
 /***********************************************************************
@@ -1994,7 +1996,7 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size
  */
 void WINAPI RtlWakeAddressAll( const void *addr )
 {
-    while (NtReleaseKeyedEvent( keyed_event, addr, 0, &zero_timeout ) == STATUS_SUCCESS) {}
+    while (NtReleaseKeyedEvent( 0, addr, 0, &zero_timeout ) == STATUS_SUCCESS) {}
 }
 
 /***********************************************************************
@@ -2002,5 +2004,5 @@ void WINAPI RtlWakeAddressAll( const void *addr )
  */
 void WINAPI RtlWakeAddressSingle( const void *addr )
 {
-    NtReleaseKeyedEvent( keyed_event, addr, 0, &zero_timeout );
+    NtReleaseKeyedEvent( 0, addr, 0, &zero_timeout );
 }
diff --git a/dlls/ntdll/tests/om.c b/dlls/ntdll/tests/om.c
index 4d879b0..7c61f39 100644
--- a/dlls/ntdll/tests/om.c
+++ b/dlls/ntdll/tests/om.c
@@ -1760,10 +1760,10 @@ static void test_keyed_events(void)
     ok( status == STATUS_TIMEOUT, "NtReleaseKeyedEvent %x\n", status );
 
     status = pNtWaitForKeyedEvent( NULL, (void *)8, 0, &timeout );
-    todo_wine ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
+    ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
         "NtWaitForKeyedEvent %x\n", status );
     status = pNtReleaseKeyedEvent( NULL, (void *)8, 0, &timeout );
-    todo_wine ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
+    ok( status == STATUS_TIMEOUT || broken(status == STATUS_INVALID_HANDLE), /* XP/2003 */
         "NtReleaseKeyedEvent %x\n", status );
 
     status = pNtWaitForKeyedEvent( (HANDLE)0xdeadbeef, (void *)9, 0, &timeout );




More information about the wine-cvs mailing list