aboutsummaryrefslogtreecommitdiffstats
path: root/lib/utils/semaphore.h
blob: c3ce736801192bd898105ccfc44cbcef33681b9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* Semaphore
* by Pierre Gaston (http://p9as.blogspot.com/2012/06/c11-semaphores.html)
* modified by Joel Low for Botan
*
*/

#ifndef BOTAN_SEMAPHORE_H__
#define BOTAN_SEMAPHORE_H__

#include <mutex>
#include <condition_variable>

namespace Botan {

class Semaphore
   {
   public:
      Semaphore(int value = 0) : m_value(value), m_wakeups(0) {}

      void acquire();

      void release(size_t n = 1);

   private:
      int m_value;
      int m_wakeups;
      std::mutex m_mutex;
      std::condition_variable m_cond;
   };

}

#endif