xtd 0.2.0
barrier.h
Go to the documentation of this file.
1 #pragma once
6 #include "cancellation_token.h"
7 #include "../action.h"
8 #include "../object.h"
9 #include "../time_span.h"
10 
12 namespace xtd {
14  namespace threading {
29  class core_export_ barrier : public object {
30  struct data;
31  public:
33 
38 
40 
45  explicit barrier(int32 participant_count);
53 
55  template <typename post_phase_action_t>
56  barrier(int32 participant_count, post_phase_action_t post_phase_action) : barrier(participant_count, barrier::post_phase_action {post_phase_action}) {}
57  barrier();
58  barrier(barrier&&) = default;
59  barrier(const barrier&) = default;
60  barrier& operator =(const barrier& other);
61  ~barrier();
63 
65 
70  int32 current_phase_number() const;
71 
75  int32 participant_count() const;
76 
81  int32 participants_remaining() const;
83 
85 
92  int32 add_participant();
93 
100  int32 add_participants(int32 participant_count);
101 
103  void close();
104 
109  int32 remove_participant();
110 
116  int32 remove_participants(int32 participant_count);
117 
121  void signal_and_wait();
128  bool signal_and_wait(int32 milliseconds_timeout);
135  bool signal_and_wait(const cancellation_token& cancellation_token);
142  bool signal_and_wait(const time_span& timeout);
151  bool signal_and_wait(int32 milliseconds_timeout, const cancellation_token& cancellation_token);
160  bool signal_and_wait(const time_span& timeout, const cancellation_token& cancellation_token);
162 
163  private:
164  bool wait_wtih_cancellation_token();
165  bool wait_wtih_cancellation_token(int32 milliseconds_timeout);
166 
167  std::shared_ptr<data> data_;
168  };
169  }
170 }
action< barrier & > post_phase_action
Represents the xtd::threading::barrier::post_phase_action delegate.
Definition: barrier.h:36
Contains xtd::threading::barrier_post_phase_exception exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Enables multiple tasks to cooperatively work on an algorithm in parallel through multiple phases...
Definition: barrier.h:29
Contains xtd::threading::cancellation_token class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Represents a time interval.
Definition: time_span.h:26
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Contains a constant used to specify an infinite amount of time. This class cannot be inherited...
Definition: timeout.h:31
delegate< void(arguments_t...)> action
Represents a xtd::delegate that has variable parameters and does not return a value.
Definition: action.h:18
Propagates notification that operations should be canceled.
Definition: cancellation_token.h:37