2 #ifndef _MADARA_NO_KARL_ 11 :
BaseContainer (
"", settings), context_ (0), id_ (0), participants_ (1)
110 MADARA_GUARD_TYPE guard (
mutex_);
112 std::stringstream buffer;
140 "Barrier::build_aggregate_barrier: building barrier string of %s\n",
141 buffer.str ().c_str ());
143 else if (
name_ ==
"")
145 context_->
print (
"ERROR: Container::Barrier needs a name.\n", 0);
149 context_->
print (
"ERROR: Container::Barrier needs a context.\n", 0);
159 MADARA_GUARD_TYPE guard (
mutex_);
161 std::stringstream buffer;
170 "Barrier::build_var: settings variable reference to %s\n",
175 else if (
name_ ==
"")
177 context_->
print (
"ERROR: Container::Barrier needs a name.\n", 0);
181 context_->
print (
"ERROR: Container::Barrier needs a context.\n", 0);
199 MADARA_GUARD_TYPE guard (
mutex_);
206 MADARA_GUARD_TYPE guard (
mutex_);
221 MADARA_GUARD_TYPE guard (
mutex_);
242 MADARA_GUARD_TYPE guard (
mutex_);
263 MADARA_GUARD_TYPE guard (
mutex_);
279 MADARA_GUARD_TYPE guard (
mutex_);
295 MADARA_GUARD_TYPE guard (
mutex_);
310 MADARA_GUARD_TYPE guard (
mutex_);
325 MADARA_GUARD_TYPE guard (
mutex_);
339 MADARA_GUARD_TYPE guard (
mutex_);
352 MADARA_GUARD_TYPE guard (
mutex_);
355 "Barrier::is_done: checking barrier result for done\n");
362 "Barrier::is_true: barrier is not true, remarking barrier variable\n");
371 "Barrier::is_true: barrier is true\n");
399 std::stringstream result;
401 result <<
"Barrier: ";
406 MADARA_GUARD_TYPE guard (
mutex_);
408 result << this->
name_;
416 std::stringstream temp_buffer;
417 temp_buffer << prefix;
422 result <<
" " << this_var;
429 return result.str ();
458 MADARA_GUARD_TYPE guard (
mutex_);
473 MADARA_GUARD_TYPE guard (
mutex_);
488 MADARA_GUARD_TYPE guard (
mutex_);
499 "Barrier::is_true: checking barrier result for truth\n");
504 MADARA_GUARD_TYPE guard (
mutex_);
509 "Barrier::is_true: final result is %d\n", (int)result);
534 #endif // _MADARA_NO_KARL_ This class encapsulates an entry in a KnowledgeBase.
bool expand_variables
Toggle for always attempting to expand variables (true) or never expanding variables (false) ...
int set(const std::string &key, T &&value, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically sets the value of a variable to the specific record.
size_t get_id(void) const
Returns the id of the barrier in the barrier ring.
size_t get_participants(void) const
Returns the number of participants in the barrier ring.
bool is_false(void) const
Determines if the barrier is false.
madara::knowledge::KnowledgeRecord get(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings()) const
Atomically returns the value of a variable.
knowledge::KnowledgeRecord::Integer to_integer(void) const
Returns the barrier round number as an integer (same as *)
std::string to_string(void) const
Returns the barrier round number as a string.
void build_aggregate_barrier(void)
Builds the aggregate barrier logic.
void operator=(const Barrier &rhs)
Assignment operator.
void resize(size_t id=0, size_t participants=1)
Resizes the barrier, usually when number of participants change.
double to_double(void) const
converts the value to a float/double
std::string name_
Prefix of variable.
virtual BaseContainer * clone(void) const
Clones this container.
bool signal_changes
Toggle whether to signal changes have happened.
knowledge::KnowledgeRecord::Integer type
trait that describes the value type
This class stores variables and their values for use by any entity needing state information in a thr...
void print(unsigned int level) const
Atomically prints all variables and values in the context.
void next(void)
Goes to the next barrier round.
size_t id_
id of this barrier in the barrier ring
MADARA_LOCK_TYPE mutex_
guard for access and changes
#define madara_logger_log(logger, level,...)
Fast version of the madara::logger::log method.
ThreadSafeContext * context_
Variable context that we are modifying.
A thread-safe guard for a context or knowledge base.
virtual void modify_(void)
Polymorphic modify method used by collection containers.
CompiledExpression aggregate_barrier_
Expression for aggregating barrier in one atomic operation.
double to_double(void) const
Returns the barrier round number as a double.
VariableReference variable_
Variable reference.
This class provides a distributed knowledge base to users.
madara::knowledge::KnowledgeRecord inc(const std::string &key, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Atomically increments the value of the variable.
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 ...
virtual std::string get_debug_info_(void)
Returns the type of the container along with name and any other useful information.
Barrier(const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Default constructor.
Integer to_integer(void) const
converts the value to an integer
type barrier_result(void) const
Checks if current barrier is successful.
bool always_overwrite
Toggle for always overwriting records, regardless of quality, clock values, etc.
CompiledExpression compile(const std::string &expression)
Compiles a KaRL expression into an expression tree.
ThreadSafeContext & get_context(void)
Returns the ThreadSafeContext associated with this Knowledge Base.
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
std::string variable_name_
Holder for variable name to quickly refresh modified status.
Provides functions and classes for the distributed knowledge base.
void init_noharm(void)
Initialize the no harm eval settings.
KnowledgeUpdateSettings settings_
Settings for modifications.
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.
EvalSettings no_harm
Settings we'll use for all evaluations.
VariableReference get_ref(const std::string &key, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings())
Atomically returns a reference to the variable.
Settings for applying knowledge updates.
bool treat_globals_as_locals
Toggle whether updates to global variables are treated as local variables and not marked as modified ...
uint32_t set_quality(const std::string &key, uint32_t quality, bool force_update, const KnowledgeReferenceSettings &settings)
Atomically sets quality of this process for a variable.
This class stores an integer within a variable context.
logger::Logger & get_logger(void) const
Gets the logger used for information printing.
void set(type value)
Sets the barrier to a specific round.
knowledge::KnowledgeRecord to_record(void) const
Returns the barrier round number as a knowledge::KnowledgeRecord.
bool delay_sending_modifieds
Toggle for sending modifieds in a single update event after each evaluation.
bool track_local_changes
Toggle for checkpointing support.
virtual bool is_true_(void) const
Polymorphic is true method which can be used to determine if all values in the container are true...
Settings for applying knowledge updates.
std::string get_debug_info(void)
Returns the type of the container along with name and any other useful information.
std::string to_string(const std::string &delimiter=", ") const
converts the value to a string.
void build_var(void)
Builds the variable that is actually incremented.
Provides an interface for external functions into the MADARA KaRL variable settings.
This class is an abstract base class for all containers.
void modify(void)
Mark the value as modified.
void mark_modified(const VariableReference &variable, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
Marks the variable reference as updated for the purposes of sending or checkpointing knowledge (for g...
ThreadSafeContext * get_context(void)
Returns the ThreadSafeContext associated with this Variables facade.