From 42e0e53be2f78ba2138260e8bd03ce3ce4d5e227 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 19 Oct 2018 11:09:10 -0500 Subject: [PATCH] common/Semaphore: Mutex -> ceph::mutex Signed-off-by: Sage Weil --- src/common/Semaphore.h | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/common/Semaphore.h b/src/common/Semaphore.h index 80153a3c16f2c..88aa9c8404f50 100644 --- a/src/common/Semaphore.h +++ b/src/common/Semaphore.h @@ -16,35 +16,30 @@ #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(); } }; -- 2.39.5