Zebediah Figura : ntdll: Try to avoid an unnecessary syscall in fast_release_srw_exclusive().

Alexandre Julliard julliard at winehq.org
Tue Jun 11 16:54:06 CDT 2019


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

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Mon Jun 10 11:07:54 2019 -0400

ntdll: Try to avoid an unnecessary syscall in fast_release_srw_exclusive().

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/sync.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c
index c7a96b6..35b89df 100644
--- a/dlls/ntdll/sync.c
+++ b/dlls/ntdll/sync.c
@@ -1667,7 +1667,10 @@ DWORD WINAPI RtlRunOnceExecuteOnce( RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN fu
  * 30-16 - Number of exclusive waiters. Unlike the fallback implementation,
  *         this does not include the thread owning the lock, or shared threads
  *         waiting on the lock.
- *  15-0 - Number of shared owners. Unlike the fallback implementation, this
+ *    15 - Does this lock have any shared waiters? We use this as an
+ *         optimization to avoid unnecessary FUTEX_WAKE_BITSET calls when
+ *         releasing an exclusive lock.
+ *  14-0 - Number of shared owners. Unlike the fallback implementation, this
  *         does not include the number of shared threads waiting on the lock.
  *         Thus the state [1, x, >=1] will never occur.
  */
@@ -1675,7 +1678,8 @@ DWORD WINAPI RtlRunOnceExecuteOnce( RTL_RUN_ONCE *once, PRTL_RUN_ONCE_INIT_FN fu
 #define SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT        0x80000000
 #define SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK    0x7fff0000
 #define SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_INC     0x00010000
-#define SRWLOCK_FUTEX_SHARED_OWNERS_MASK        0x0000ffff
+#define SRWLOCK_FUTEX_SHARED_WAITERS_BIT        0x00008000
+#define SRWLOCK_FUTEX_SHARED_OWNERS_MASK        0x00007fff
 #define SRWLOCK_FUTEX_SHARED_OWNERS_INC         0x00000001
 
 /* Futex bitmasks; these are independent from the bits in the lock itself. */
@@ -1810,7 +1814,7 @@ static NTSTATUS fast_acquire_srw_shared( RTL_SRWLOCK *lock )
             }
             else
             {
-                new = old;
+                new = old | SRWLOCK_FUTEX_SHARED_WAITERS_BIT;
                 wait = TRUE;
             }
         } while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
@@ -1841,11 +1845,14 @@ static NTSTATUS fast_release_srw_exclusive( RTL_SRWLOCK *lock )
         }
 
         new = old & ~SRWLOCK_FUTEX_EXCLUSIVE_LOCK_BIT;
+
+        if (!(new & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK))
+            new &= ~SRWLOCK_FUTEX_SHARED_WAITERS_BIT;
     } while (interlocked_cmpxchg( (int *)lock, new, old ) != old);
 
     if (new & SRWLOCK_FUTEX_EXCLUSIVE_WAITERS_MASK)
         futex_wake_bitset( (int *)lock, 1, SRWLOCK_FUTEX_BITSET_EXCLUSIVE );
-    else
+    else if (old & SRWLOCK_FUTEX_SHARED_WAITERS_BIT)
         futex_wake_bitset( (int *)lock, INT_MAX, SRWLOCK_FUTEX_BITSET_SHARED );
 
     return STATUS_SUCCESS;




More information about the wine-cvs mailing list