]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Semaphore: Mutex -> ceph::mutex
authorSage Weil <sage@redhat.com>
Fri, 19 Oct 2018 16:09:10 +0000 (11:09 -0500)
committerKefu Chai <kchai@redhat.com>
Wed, 21 Nov 2018 03:56:33 +0000 (11:56 +0800)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/Semaphore.h

index 80153a3c16f2ca058bd579d49943ea204c9acaef..88aa9c8404f50beb1235a7852055aabcd08141bf 100644 (file)
 #ifndef CEPH_Sem_Posix__H
 #define CEPH_Sem_Posix__H
 
+#include "common/ceph_mutex.h"
+
 class Semaphore
 {
-  Mutex m;
-  Cond c;
-  int count;
+  ceph::mutex m = ceph::make_mutex("Semaphore::m");
+  ceph::condition_variable c;
+  int count = 0;
 
   public:
 
-  Semaphore() : m("Semaphore::m")
-  {
-    count = 0;
-  }
-
   void Put()
   { 
-    m.lock();
+    std::lock_guard l(m);
     count++;
-    c.Signal();
-    m.unlock();
+    c.notify_all();
   }
 
   void Get() 
-  { 
-    m.lock();
+  {
+    std::unique_lock l(m);
     while(count <= 0) {
-      c.Wait(m);
+      c.wait(l);
     }
     count--;
-    m.unlock();
   }
 };