Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
barrier.h
Go to the documentation of this file.
1 
18 #ifndef ION_PORT_BARRIER_H_
19 #define ION_PORT_BARRIER_H_
20 
21 #if defined(ION_PLATFORM_WINDOWS)
22 # include <windows.h>
23 #else
24 # include <pthread.h>
25 #endif
26 
27 #include "base/integral_types.h"
28 #include "base/macros.h"
29 #include "ion/port/atomic.h"
30 
31 namespace ion {
32 namespace port {
33 
38 class Barrier {
39  public:
43  explicit Barrier(uint32 thread_count);
44  ~Barrier();
45 
48  bool IsValid() const { return is_valid_; }
49 
51  void Wait();
52 
53  private:
54 #if defined(ION_PLATFORM_WINDOWS)
55  void WaitInternal(int32 increment, int32 limit, HANDLE turnstile);
58 
59  const int32 thread_count_;
60  std::atomic<int32> wait_count_;
61  HANDLE turnstile1_;
62  HANDLE turnstile2_;
63 #elif defined(ION_PLATFORM_LINUX) || defined(ION_PLATFORM_QNX)
64  pthread_barrier_t barrier_;
68  std::atomic<int32> waiting_count_;
69 #else
70  pthread_cond_t condition_;
72  pthread_cond_t exit_condition_;
73  pthread_mutex_t mutex_;
74  const int32 thread_count_;
75  int32 wait_count_;
76  int32 exit_count_;
77 #endif
78  bool is_valid_;
80 
81  DISALLOW_COPY_AND_ASSIGN(Barrier);
82 };
83 
84 } // namespace port
85 } // namespace ion
86 
87 #endif // ION_PORT_BARRIER_H_
The Barrier class defines a multi-thread barrier that allows N threads to synchronize execution...
Definition: barrier.h:38
void Wait()
Causes the current thread to wait at the barrier.
Definition: barrier.cc:182
Barrier(uint32 thread_count)
Constructs an instance that will wait for thread_count threads.
Definition: barrier.cc:156
bool IsValid() const
Returns true if a valid barrier was created by the constructor.
Definition: barrier.h:48