]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/RWLock.h
update sources to v12.1.0
[ceph.git] / ceph / src / common / RWLock.h
index befc5a53ce3c592364237999d5bbd76948f723b3..fd8a2665ef18f657d4c9b4d2939e5ea908068cbe 100644 (file)
 #include <string>
 #include <include/assert.h>
 #include "lockdep.h"
-#include "include/atomic.h"
 #include "common/valgrind.h"
 
+#include <atomic>
+
 class RWLock final
 {
   mutable pthread_rwlock_t L;
   std::string name;
   mutable int id;
-  mutable atomic_t nrlock, nwlock;
+  mutable std::atomic<unsigned> nrlock = { 0 }, nwlock = { 0 };
   bool track, lockdep;
 
   std::string unique_name(const char* name) const;
@@ -39,7 +40,7 @@ public:
   const RWLock& operator=(const RWLock& other) = delete;
 
   RWLock(const std::string &n, bool track_lock=true, bool ld=true, bool prioritize_write=false)
-    : name(n), id(-1), nrlock(0), nwlock(0), track(track_lock),
+    : name(n), id(-1), track(track_lock),
       lockdep(ld) {
 #if defined(PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP)
     if (prioritize_write) {
@@ -65,12 +66,12 @@ public:
 
   bool is_locked() const {
     assert(track);
-    return (nrlock.read() > 0) || (nwlock.read() > 0);
+    return (nrlock > 0) || (nwlock > 0);
   }
 
   bool is_wlocked() const {
     assert(track);
-    return (nwlock.read() > 0);
+    return (nwlock > 0);
   }
   ~RWLock() {
     // The following check is racy but we are about to destroy
@@ -85,11 +86,11 @@ public:
 
   void unlock(bool lockdep=true) const {
     if (track) {
-      if (nwlock.read() > 0) {
-        nwlock.dec();
+      if (nwlock > 0) {
+        nwlock--;
       } else {
-        assert(nrlock.read() > 0);
-        nrlock.dec();
+        assert(nrlock > 0);
+        nrlock--;
       }
     }
     if (lockdep && this->lockdep && g_lockdep)
@@ -105,12 +106,12 @@ public:
     assert(r == 0);
     if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
     if (track)
-      nrlock.inc();
+      nrlock++;
   }
   bool try_get_read() const {
     if (pthread_rwlock_tryrdlock(&L) == 0) {
       if (track)
-         nrlock.inc();
+         nrlock++;
       if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
       return true;
     }
@@ -129,7 +130,7 @@ public:
     if (lockdep && this->lockdep && g_lockdep)
       id = lockdep_locked(name.c_str(), id);
     if (track)
-      nwlock.inc();
+      nwlock++;
 
   }
   bool try_get_write(bool lockdep=true) {
@@ -137,7 +138,7 @@ public:
       if (lockdep && this->lockdep && g_lockdep)
        id = lockdep_locked(name.c_str(), id);
       if (track)
-         nwlock.inc();
+         nwlock++;
       return true;
     }
     return false;