MADARA  3.4.1
Barrier.h
Go to the documentation of this file.
1 
2 #ifndef _MADARA_CONTAINERS_BARRIER_H_
3 #define _MADARA_CONTAINERS_BARRIER_H_
4 
5 #include <vector>
6 #include <string>
7 #include "madara/LockType.h"
12 #include "BaseContainer.h"
13 
22 namespace madara
23 {
24 namespace knowledge
25 {
26 namespace containers
27 {
32 class MADARA_EXPORT Barrier : public BaseContainer
33 {
34 public:
37 
42 
51 
58  Barrier(const std::string& name, Variables& knowledge,
60 
69  Barrier(const std::string& name, KnowledgeBase& knowledge, int id,
70  int participants,
72 
81  Barrier(const std::string& name, Variables& knowledge, int id,
82  int participants,
84 
88  Barrier(const Barrier& rhs);
89 
93  ~Barrier();
94 
99  void operator=(const Barrier& rhs);
100 
105  size_t get_id(void) const;
106 
111  size_t get_participants(void) const;
112 
117  inline type get_round(void) const
118  {
119  return to_integer();
120  }
121 
126  void set(type value);
127 
135  void set_name(const std::string& var_name, KnowledgeBase& knowledge, int id,
136  int participants);
137 
145  void set_name(const std::string& var_name, Variables& knowledge, int id,
146  int participants);
147 
155  void set_name(const std::string& var_name, ThreadSafeContext& knowledge,
156  int id, int participants);
157 
163  type operator=(type value);
164 
168  void next(void);
169 
174  bool is_done(void);
175 
180  void modify(void);
181 
187  knowledge::KnowledgeRecord to_record(void) const;
188 
193  double to_double(void) const;
194 
199  knowledge::KnowledgeRecord::Integer to_integer(void) const;
200 
205  std::string to_string(void) const;
206 
212  bool operator==(const Barrier& value) const;
213 
219  bool operator!=(const Barrier& value) const;
220 
227  void set_quality(uint32_t quality,
229  false));
230 
236  void resize(size_t id = 0, size_t participants = 1);
237 
247  std::string get_debug_info(void);
248 
254  virtual BaseContainer* clone(void) const;
255 
260  bool is_true(void) const;
261 
266  bool is_false(void) const;
267 
268 private:
273  virtual bool is_true_(void) const;
274 
279  virtual bool is_false_(void) const;
280 
289  virtual void modify_(void);
290 
300  virtual std::string get_debug_info_(void);
301 
305  void build_aggregate_barrier(void);
306 
311  inline type barrier_result(void) const
312  {
313  type result = 1;
314 
315  // check the barriers for
316  for ( ; last_failed_check_ < participants_ ; ++last_failed_check_)
317  {
318  // this guy isn't up to our barrier yet?
319  if (barrier_[last_failed_check_] < *barrier_[id_])
320  {
321  // load from the kb to check for updates
322  barrier_[last_failed_check_].read();
323 
324  // if he's still not up to our barrier yet, the barrier isn't done
325  if (barrier_[last_failed_check_] < *barrier_[id_])
326  {
327  result = 0;
328  break;
329  }
330  }
331  }
332 
333  return result;
334  }
335 
340 
344  size_t id_;
345 
350 
354  mutable size_t last_failed_check_;
355 
356  mutable std::vector<IntegerStaged> barrier_;
357 };
358 } // namespace containers
359 } // namespace knowledge
360 } // namespace madara
361 
362 #endif // _MADARA_CONTAINERS_BARRIER_H_
This class provides a distributed knowledge base to users.
Definition: KnowledgeBase.h:45
This class encapsulates an entry in a KnowledgeBase.
Settings for applying knowledge updates.
Settings for applying knowledge updates.
This class stores variables and their values for use by any entity needing state information in a thr...
Provides an interface for external functions into the MADARA KaRL variable settings.
Definition: Variables.h:53
This class stores an integer within a variable context.
Definition: Barrier.h:33
size_t last_failed_check_
id of this barrier in the barrier ring
Definition: Barrier.h:354
bool operator==(const Barrier &value) const
Checks for equality.
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
Definition: Barrier.h:36
type get_round(void) const
Returns the current barrier round.
Definition: Barrier.h:117
type barrier_result(void) const
Checks if current barrier is successful.
Definition: Barrier.h:311
size_t participants_
the number of participants in the barrier ring
Definition: Barrier.h:349
std::vector< IntegerStaged > barrier_
Definition: Barrier.h:356
size_t id_
id of this barrier in the barrier ring
Definition: Barrier.h:344
bool operator!=(const Barrier &value) const
Checks for inequality.
ThreadSafeContext * context_
Variable context that we are modifying.
Definition: Barrier.h:339
This class is an abstract base class for all containers.
Definition: BaseContainer.h:34
Provides container classes for fast knowledge base access and mutation.
Definition: Barrier.h:27
constexpr string_t string
Provides functions and classes for the distributed knowledge base.
Copyright(c) 2020 Galois.