CyclicBarrier.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_CONCURRENT__CYCLIC_BARRIER
18 #define COM_BORA_SOFTWARE__BALAU_CONCURRENT__CYCLIC_BARRIER
19 
21 
22 namespace Balau {
23 
24 class Logger;
25 
26 namespace Concurrent {
27 
41  public: explicit CyclicBarrier(unsigned int count_)
42  : turnstile1(0)
43  , turnstile2(1)
44  , number(count_),
45  count(count_) {}
46 
53  public: void reconfigure(unsigned int count_) {
54  std::lock_guard<std::mutex> lock(mutex);
55  number = count_;
56  count = count_;
57  }
58 
62  public: void countdown();
63 
65 
66  private: static Logger & LOG();
67 
68  private: std::mutex mutex;
69  private: Semaphore turnstile1;
70  private: Semaphore turnstile2;
71  private: int number;
72  private: int count;
73 };
74 
75 } // namespace Concurrent
76 
77 } // namespace Balau
78 
79 #endif // COM_BORA_SOFTWARE__BALAU_CONCURRENT__CYCLIC_BARRIER
CyclicBarrier(unsigned int count_)
Create a cyclic barrier with the specified count.
Definition: CyclicBarrier.hpp:41
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
Traditional semaphore synchronisation object.
Traditional semaphore synchronisation object.
Definition: Semaphore.hpp:27
The main logger class.
Definition: Logger.hpp:92
A synchronising barrier that can be configured for an arbitrary number of threads.
Definition: CyclicBarrier.hpp:37
void countdown()
Count down the barrier, blocking if the count has not reached 0.
void reconfigure(unsigned int count_)
Reconfigure the latch to count the specified number of times.
Definition: CyclicBarrier.hpp:53