]> git.kaiwu.me - nginx.git/commitdiff
Core: simplify reader lock release.
authorPavel Pautov <p.pautov@f5.com>
Thu, 20 Jan 2022 01:37:34 +0000 (17:37 -0800)
committerPavel Pautov <p.pautov@f5.com>
Thu, 20 Jan 2022 01:37:34 +0000 (17:37 -0800)
src/core/ngx_rwlock.c

index ed2b0f81050d325f8ee08d3053d0e2bb528c04af..e7da8a8ec55a6963455360a791e28ccdda8971f4 100644 (file)
@@ -89,22 +89,10 @@ ngx_rwlock_rlock(ngx_atomic_t *lock)
 void
 ngx_rwlock_unlock(ngx_atomic_t *lock)
 {
-    ngx_atomic_uint_t  readers;
-
-    readers = *lock;
-
-    if (readers == NGX_RWLOCK_WLOCK) {
+    if (*lock == NGX_RWLOCK_WLOCK) {
         (void) ngx_atomic_cmp_set(lock, NGX_RWLOCK_WLOCK, 0);
-        return;
-    }
-
-    for ( ;; ) {
-
-        if (ngx_atomic_cmp_set(lock, readers, readers - 1)) {
-            return;
-        }
-
-        readers = *lock;
+    } else {
+        (void) ngx_atomic_fetch_add(lock, -1);
     }
 }