From: Sage Weil Date: Fri, 19 Oct 2018 16:09:10 +0000 (-0500) Subject: common/Semaphore: Mutex -> ceph::mutex X-Git-Tag: v14.1.0~820^2~20 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=42e0e53be2f78ba2138260e8bd03ce3ce4d5e227;p=ceph.git common/Semaphore: Mutex -> ceph::mutex Signed-off-by: Sage Weil --- diff --git a/src/common/Semaphore.h b/src/common/Semaphore.h index 80153a3c16f2..88aa9c8404f5 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(); } };