Samchon Framework for CPP  1.0.0
Semaphore.hpp
1 #pragma once
2 #include <samchon/API.hpp>
3 
4 namespace std
5 {
6  template <typename T> struct atomic;
7  class mutex;
8 };
9 namespace samchon
10 {
11 namespace library
12 {
51  class SAMCHON_FRAMEWORK_API Semaphore
52  {
53  private:
58  size_t size_;
59 
60  /* ====================================================
61  VARIABLES FOR LOCK
62  ==================================================== */
66  size_t acquired;
67  std::mutex *countMtx;
68 
73  std::mutex *mtx;
74 
75  public:
81  Semaphore(size_t = 2);
82  ~Semaphore();
83 
88  void setSize(size_t);
89 
90  /* ====================================================
91  GETTERS
92  ==================================================== */
99  auto size() const->size_t;
100 
104  auto acquiredSize() const->size_t;
105 
106  /* ====================================================
107  LOCKERS
108  ==================================================== */
117  void acquire();
118 
132  auto tryAcquire() -> bool;
133 
141  void release();
142  };
143 };
144 };
145 
146 #include <samchon/library/UniqueAcquire.hpp>
147 #include <samchon/library/SharedAcquire.hpp>
Definition: RWMutex.hpp:4
std::mutex * mtx
Locker.
Definition: Semaphore.hpp:73
size_t size_
The size.
Definition: Semaphore.hpp:58
size_t acquired
Acquired count.
Definition: Semaphore.hpp:66
Top level namespace of products built from samchon.
Definition: ByteArray.hpp:7