From 057aaef5d4584ab25143885e9ae9bbc1b347c7e6 Mon Sep 17 00:00:00 2001 From: sbrandt Date: Wed, 22 Jun 2005 04:44:26 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@332 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/common/Semaphore.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ceph/common/Semaphore.h diff --git a/ceph/common/Semaphore.h b/ceph/common/Semaphore.h new file mode 100644 index 00000000000..f8821f7c686 --- /dev/null +++ b/ceph/common/Semaphore.h @@ -0,0 +1,37 @@ +#ifndef _Sem_Posix_ +#define _Sem_Posix_ + +#include + +class Semaphore +{ + Mutex m; + Cond c; + int count; + + public: + + Semaphore() + { + count = 0; + } + + void Put() { + m.Lock(); + count++; + c.Signal(); + m.Unlock(); + } + + void Get() + { + m.Lock(); + while(count <= 0) { + C.Wait(m); + } + count--; + m.Unlock(); + } +}; + +#endif // !_Mutex_Posix_