Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / common / Semaphore.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software 
11  * Foundation.  See file COPYING.
12  * 
13  */
14
15
16 #ifndef CEPH_Sem_Posix__H
17 #define CEPH_Sem_Posix__H
18
19 class Semaphore
20 {
21   Mutex m;
22   Cond c;
23   int count;
24
25   public:
26
27   Semaphore() : m("Semaphore::m")
28   {
29     count = 0;
30   }
31
32   void Put()
33   { 
34     m.Lock();
35     count++;
36     c.Signal();
37     m.Unlock();
38   }
39
40   void Get() 
41   { 
42     m.Lock();
43     while(count <= 0) {
44       c.Wait(m);
45     }
46     count--;
47     m.Unlock();
48   }
49 };
50
51 #endif // !_Mutex_Posix_