43 participants_(participants),
55 participants_(participants),
65 participants_(rhs.participants_),
66 last_failed_check_(rhs.last_failed_check_),
67 barrier_(rhs.barrier_)
77 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
80 this->name_ = rhs.
name_;
94 MADARA_GUARD_TYPE guard(mutex_);
96 barrier_.resize(participants_);
99 for (
size_t i = 0; i < participants_; ++i)
101 std::stringstream buffer;
106 barrier_[i].set_name(buffer.str(), *
context_);
110 barrier_[id_].write();
113 "Barrier::build_aggregate_barrier: built %d member barrier\n",
116 else if (name_ ==
"")
118 context_->print(
"ERROR: containers::Barrier needs a name.\n", 0);
129 MADARA_GUARD_TYPE guard(mutex_);
135 MADARA_GUARD_TYPE guard(mutex_);
136 return participants_;
147 MADARA_GUARD_TYPE guard(mutex_);
151 participants_ = participants;
152 last_failed_check_ = 0;
154 this->build_aggregate_barrier();
164 MADARA_GUARD_TYPE guard(mutex_);
168 participants_ = participants;
169 last_failed_check_ = 0;
171 this->build_aggregate_barrier();
182 MADARA_GUARD_TYPE guard(mutex_);
186 participants_ = participants;
187 last_failed_check_ = 0;
189 this->build_aggregate_barrier();
193 size_t id,
size_t participants)
198 MADARA_GUARD_TYPE guard(mutex_);
201 participants_ = participants;
202 last_failed_check_ = 0;
204 this->build_aggregate_barrier();
214 MADARA_GUARD_TYPE guard(mutex_);
216 barrier_[id_] = value;
218 last_failed_check_ = 0;
231 result = *barrier_[id_];
244 result = *barrier_[id_];
255 last_failed_check_ = 0;
256 barrier_[id_].write();
267 MADARA_GUARD_TYPE guard(mutex_);
270 "Barrier::is_done: checking barrier result for done\n");
272 result = barrier_result() == 1;
277 "Barrier::is_true: barrier is not true, remarking barrier "
280 barrier_[id_].write();
287 "Barrier::is_true: barrier is true\n");
298 barrier_[id_] = value;
306 barrier_[id_].write();
312 std::stringstream result;
314 result <<
"Barrier: ";
320 for (
size_t i = 0; i < participants_; ++i)
325 result << barrier_[i].get_name();
327 result << *barrier_[i];
342 return get_debug_info();
357 result = barrier_[id_].to_double();
369 result = barrier_[id_].to_string();
380 barrier_[id_].set_quality(quality, settings);
389 "Barrier::is_true: checking barrier result for truth\n");
397 result = barrier_result() == 1;
401 "Barrier::is_true: final result is %d\n", (
int)result);
#define madara_logger_log(loggering, level,...)
Fast version of the madara::logger::log method.
const ThreadSafeContext * context_
A thread-safe guard for a context or knowledge base.
This class provides a distributed knowledge base to users.
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.
This class stores an integer within a variable context.
knowledge::KnowledgeRecord to_record(void) const
Returns the barrier round number as a knowledge::KnowledgeRecord.
size_t get_id(void) const
Returns the id of the barrier in the barrier ring.
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the barrier round number as an integer (same as *)
bool is_false(void) const
Determines if the barrier is false.
size_t get_participants(void) const
Returns the number of participants in the barrier ring.
size_t last_failed_check_
id of this barrier in the barrier ring
std::string to_string(void) const
Returns the barrier round number as a string.
void resize(size_t id=0, size_t participants=1)
Resizes the barrier, usually when number of participants change.
virtual bool is_false_(void) const
Polymorphic is false method which can be used to determine if at least one value in the container is ...
double to_double(void) const
Returns the barrier round number as a double.
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
void set_quality(uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to the barrier variables.
size_t participants_
the number of participants in the barrier ring
void next(void)
Goes to the next barrier round.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true.
std::vector< IntegerStaged > barrier_
virtual void modify_(void)
Polymorphic modify method used by collection containers.
size_t id_
id of this barrier in the barrier ring
void set(type value)
Sets the barrier to a specific round.
virtual BaseContainer * clone(void) const
Clones this container.
void modify(void)
Mark the value as modified.
Barrier(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
void build_aggregate_barrier(void)
Builds the aggregate barrier logic.
bool is_true(void) const
Determines if the barrier is true.
bool is_done(void)
Wait for all other participants to reach your barrier round.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int id, int participants)
Sets the variable name that this refers to.
ThreadSafeContext * context_
Variable context that we are modifying.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
void operator=(const Barrier &rhs)
Assignment operator.
This class is an abstract base class for all containers.
KnowledgeUpdateSettings settings_
Settings for modifications.
std::string name_
Prefix of variable.
MADARA_LOCK_TYPE mutex_
guard for access and changes
Provides functions and classes for the distributed knowledge base.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger