TDME2  1.9.200
Condition.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <tdme/tdme.h>
6 
7 #include <condition_variable>
8 #include <mutex>
9 #include <string>
10 
12 
13 using std::condition_variable_any;
14 using std::mutex;
15 using std::string;
16 
18 
19 /**
20 * Threading condition variable implementation
21 * @author Andreas Drewke
22 */
24 public:
25  // forbid class copy
27 
28  /**
29  * @brief Public constructor, creates condition variable
30  * @param name string
31  */
32  inline Condition(const string& name): name(name) {}
33 
34  /**
35  * @brief Destructor, removes condition variable
36  */
37  inline ~Condition() {}
38 
39  /**
40  * @brief wake ups a waiting thread on this condition, associated mutex should protect signal
41  */
42  inline void signal() {
43  stlCondition.notify_one();
44  }
45 
46  /**
47  * @brief wake ups all waiting threads on this condition, associated mutex should protect broadcast
48  */
49  inline void broadcast() {
50  stlCondition.notify_all();
51  }
52 
53  /**
54  * @brief Blocks current thread until signaled/broadcasted, associated mutex should protect wait
55  */
56  inline void wait(Mutex &mutex) {
57  stlCondition.wait(mutex.stlMutex);
58  }
59 
60 private:
61  string name;
62  condition_variable_any stlCondition;
63 };
Threading condition variable implementation.
Definition: Condition.h:23
void broadcast()
wake ups all waiting threads on this condition, associated mutex should protect broadcast
Definition: Condition.h:49
void signal()
wake ups a waiting thread on this condition, associated mutex should protect signal
Definition: Condition.h:42
~Condition()
Destructor, removes condition variable.
Definition: Condition.h:37
condition_variable_any stlCondition
Definition: Condition.h:62
void wait(Mutex &mutex)
Blocks current thread until signaled/broadcasted, associated mutex should protect wait.
Definition: Condition.h:56
Mutex implementation.
Definition: Mutex.h:19
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6