45 participants_(participants)
58 participants_(participants)
68 variable_(rhs.variable_),
70 participants_(rhs.participants_),
71 #ifndef _MADARA_NO_KARL_
72 aggregate_barrier_(rhs.aggregate_barrier_),
74 variable_name_(rhs.variable_name_)
84 MADARA_GUARD_TYPE guard(mutex_), guard2(rhs.
mutex_);
87 this->name_ = rhs.
name_;
92 #ifndef _MADARA_NO_KARL_
104 MADARA_GUARD_TYPE guard(mutex_);
106 std::stringstream buffer;
107 if (participants_ > 0)
117 for (
size_t i = 1; i < participants_; ++i)
130 #ifndef _MADARA_NO_KARL_
131 aggregate_barrier_ =
context_->compile(buffer.str());
135 "LegacyBarrier::build_aggregate_barrier: building barrier string of %s\n",
136 buffer.str().c_str());
138 else if (name_ ==
"")
140 context_->print(
"ERROR: containers::LegacyBarrier needs a name.\n", 0);
154 MADARA_GUARD_TYPE guard(mutex_);
156 std::stringstream buffer;
162 variable_name_ = buffer.str();
165 "LegacyBarrier::build_var: settings variable reference to %s\n",
166 variable_name_.c_str());
168 variable_ =
context_->get_ref(buffer.str(), no_harm);
170 else if (name_ ==
"")
172 context_->print(
"ERROR: Container::LegacyBarrier needs a name.\n", 0);
183 no_harm.always_overwrite =
false;
184 no_harm.delay_sending_modifieds =
true;
185 no_harm.expand_variables =
false;
186 no_harm.signal_changes =
false;
187 no_harm.track_local_changes =
false;
188 no_harm.treat_globals_as_locals =
true;
193 MADARA_GUARD_TYPE guard(mutex_);
199 MADARA_GUARD_TYPE guard(mutex_);
200 return participants_;
211 MADARA_GUARD_TYPE guard(mutex_);
215 participants_ = participants;
218 this->build_aggregate_barrier();
228 MADARA_GUARD_TYPE guard(mutex_);
232 participants_ = participants;
235 this->build_aggregate_barrier();
246 MADARA_GUARD_TYPE guard(mutex_);
250 participants_ = participants;
253 this->build_aggregate_barrier();
257 size_t id,
size_t participants)
262 MADARA_GUARD_TYPE guard(mutex_);
265 participants_ = participants;
268 this->build_aggregate_barrier();
278 MADARA_GUARD_TYPE guard(mutex_);
279 context_->set(variable_, value, settings_);
293 MADARA_GUARD_TYPE guard(mutex_);
294 result =
context_->get(variable_, no_harm);
308 MADARA_GUARD_TYPE guard(mutex_);
309 result =
context_->get(variable_, no_harm).to_integer();
320 MADARA_GUARD_TYPE guard(mutex_);
321 context_->inc(variable_, settings_);
332 MADARA_GUARD_TYPE guard(mutex_);
335 "LegacyBarrier::is_done: checking barrier result for done\n");
337 result = barrier_result() == 1;
342 "LegacyBarrier::is_true: barrier is not true, remarking barrier "
352 "LegacyBarrier::is_true: barrier is true\n");
363 context_->set(variable_, value, settings_);
377 std::stringstream result;
379 result <<
"LegacyBarrier: ";
384 MADARA_GUARD_TYPE guard(mutex_);
386 result << this->name_;
387 result <<
" = " <<
context_->get(variable_).to_string() <<
"\n";
392 for (
size_t i = 0; i < participants_; ++i)
394 std::stringstream temp_buffer;
395 temp_buffer << prefix;
400 result <<
" " << this_var;
417 return get_debug_info();
433 MADARA_GUARD_TYPE guard(mutex_);
434 result =
context_->get(variable_, no_harm).to_double();
447 MADARA_GUARD_TYPE guard(mutex_);
448 result =
context_->get(variable_, no_harm).to_string();
460 MADARA_GUARD_TYPE guard(mutex_);
461 context_->set_quality(name_, quality,
true, settings);
470 "LegacyBarrier::is_true: checking barrier result for truth\n");
475 MADARA_GUARD_TYPE guard(mutex_);
476 result = barrier_result() == 1;
480 "LegacyBarrier::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 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
This class stores an integer within a variable context.
size_t get_participants(void) const
Returns the number of participants in the barrier ring.
ThreadSafeContext * context_
Variable context that we are modifying.
knowledge::KnowledgeRecord to_record(void) const
Returns the barrier round number as a knowledge::KnowledgeRecord.
void resize(size_t id=0, size_t participants=1)
Resizes the barrier, usually when number of participants change.
bool is_false(void) const
Determines if the barrier is false.
double to_double(void) const
Returns the barrier round number as a double.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
void build_aggregate_barrier(void)
Builds the aggregate barrier logic.
void set_name(const std::string &var_name, KnowledgeBase &knowledge, int id, int participants)
Sets the variable name that this refers to.
VariableReference variable_
Variable reference.
void build_var(void)
Builds the variable that is actually incremented.
size_t id_
id of this barrier in the barrier ring
virtual BaseContainer * clone(void) const
Clones this container.
bool is_true(void) const
Determines if the barrier is true.
~LegacyBarrier()
Destructor.
void operator=(const LegacyBarrier &rhs)
Assignment operator.
size_t participants_
the number of participants in the barrier ring
LegacyBarrier(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
void modify(void)
Mark the value as modified.
void set_quality(uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
Sets the quality of writing to the barrier variables.
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::string variable_name_
Holder for variable name to quickly refresh modified status.
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
void init_noharm(void)
Initialize the no harm eval settings.
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the barrier round number as an integer (same as *)
void next(void)
Goes to the next barrier round.
CompiledExpression aggregate_barrier_
Expression for aggregating barrier in one atomic operation.
void set(type value)
Sets the barrier to a specific round.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
size_t get_id(void) const
Returns the id of the barrier in the barrier ring.
std::string to_string(void) const
Returns the barrier round number as a string.
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 ...
bool is_done(void)
Wait for all other participants to reach your barrier round.
Provides functions and classes for the distributed knowledge base.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger