mirror of
https://github.com/ceph/ceph
synced 2024-12-18 01:16:55 +00:00
*** empty log message ***
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@332 29311d96-e01e-0410-9327-a35deaab8ce9
This commit is contained in:
parent
94ade9d913
commit
057aaef5d4
37
ceph/common/Semaphore.h
Normal file
37
ceph/common/Semaphore.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef _Sem_Posix_
|
||||
#define _Sem_Posix_
|
||||
|
||||
#include <cassert>
|
||||
|
||||
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_
|
Loading…
Reference in New Issue
Block a user