TDME2  1.9.200
Barrier.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <tdme/tdme.h>
6 
7 #include <string>
8 
11 
12 using std::string;
13 
16 
17 /**
18  * Barrier implementation.
19  * @author Andreas Drewke
20  */
22 public:
23  // forbid class copy
25 
26  /**
27  * @brief Public constructor
28  * @param name name
29  * @param count Number of threads that need to "wait" on barrier to complete barrier
30  */
31  inline Barrier(const string& name, const unsigned int count): name(name), count(count), entered(0), exited(0), m("barrier_mutex"), c("barrier_condition") {}
32 
33  /**
34  * @brief Destroys the barrier
35  */
36  ~Barrier();
37 
38  /**
39  * @brief Waits on barrier
40  * @return bool if caller thread is selected for updating shared data
41  */
42  bool wait();
43 
44 private:
45  string name;
46  unsigned int count;
47  volatile unsigned int entered;
48  volatile unsigned int exited;
51 };
Barrier implementation.
Definition: Barrier.h:21
~Barrier()
Destroys the barrier.
Definition: Barrier.cpp:14
volatile unsigned int exited
Definition: Barrier.h:48
bool wait()
Waits on barrier.
Definition: Barrier.cpp:28
volatile unsigned int entered
Definition: Barrier.h:47
Threading condition variable implementation.
Definition: Condition.h:23
Mutex implementation.
Definition: Mutex.h:19
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6