MADARA  3.2.3
madara::knowledge::containers::Barrier Class Reference

This class stores an integer within a variable context. More...

#include <Barrier.h>

Inheritance diagram for madara::knowledge::containers::Barrier:
madara::knowledge::containers::BaseContainer

Public Types

typedef knowledge::KnowledgeRecord::Integer type
 trait that describes the value type More...
 

Public Member Functions

 Barrier (const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 Barrier (const std::string &name, KnowledgeBase &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Constructor. More...
 
 Barrier (const std::string &name, Variables &knowledge, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Constructor. More...
 
 Barrier (const std::string &name, KnowledgeBase &knowledge, int id, int participants, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 Barrier (const std::string &name, Variables &knowledge, int id, int participants, const KnowledgeUpdateSettings &settings=KnowledgeUpdateSettings())
 Default constructor. More...
 
 Barrier (const Barrier &rhs)
 Copy constructor. More...
 
 ~Barrier ()
 Destructor. More...
 
virtual BaseContainerclone (void) const
 Clones this container. More...
 
std::string get_debug_info (void)
 Returns the type of the container along with name and any other useful information. More...
 
size_t get_id (void) const
 Returns the id of the barrier in the barrier ring. More...
 
std::string get_name (void) const
 Returns the name of the container. More...
 
size_t get_participants (void) const
 Returns the number of participants in the barrier ring. More...
 
type get_round (void) const
 Returns the current barrier round. More...
 
KnowledgeUpdateSettings get_settings (void)
 Gets the update settings for the container. More...
 
bool is_done (void)
 Wait for all other participants to reach your barrier round. More...
 
bool is_false (void) const
 Determines if the barrier is false. More...
 
bool is_true (void) const
 Determines if the barrier is true. More...
 
void modify (void)
 Mark the value as modified. More...
 
virtual bool modify_if_false (BaseContainer &conditional)
 Modifies the container if the argument is false. More...
 
virtual bool modify_if_true (BaseContainer &conditional)
 Modifies the container if the argument is true. More...
 
void next (void)
 Goes to the next barrier round. More...
 
bool operator!= (const Barrier &value) const
 Checks for inequality. More...
 
void operator= (const Barrier &rhs)
 Assignment operator. More...
 
type operator= (type value)
 Sets the value of the variable. More...
 
bool operator== (const Barrier &value) const
 Checks for equality. More...
 
void resize (size_t id=0, size_t participants=1)
 Resizes the barrier, usually when number of participants change. More...
 
void set (type value)
 Sets the barrier to a specific round. More...
 
void set_name (const std::string &var_name, KnowledgeBase &knowledge, int id, int participants)
 Sets the variable name that this refers to. More...
 
void set_name (const std::string &var_name, Variables &knowledge, int id, int participants)
 Sets the variable name that this refers to. More...
 
void set_name (const std::string &var_name, ThreadSafeContext &knowledge, int id, int participants)
 Sets the variable name that this refers to. More...
 
void set_quality (uint32_t quality, const KnowledgeReferenceSettings &settings=KnowledgeReferenceSettings(false))
 Sets the quality of writing to the barrier variables. More...
 
void set_settings (const KnowledgeUpdateSettings &settings)
 Sets the update settings for the container. More...
 
double to_double (void) const
 Returns the barrier round number as a double. More...
 
knowledge::KnowledgeRecord::Integer to_integer (void) const
 Returns the barrier round number as an integer (same as *) More...
 
knowledge::KnowledgeRecord to_record (void) const
 Returns the barrier round number as a knowledge::KnowledgeRecord. More...
 
std::string to_string (void) const
 Returns the barrier round number as a string. More...
 

Protected Attributes

MADARA_LOCK_TYPE mutex_
 guard for access and changes More...
 
std::string name_
 Prefix of variable. More...
 
KnowledgeUpdateSettings settings_
 Settings for modifications. More...
 

Private Member Functions

type barrier_result (void) const
 Checks if current barrier is successful. More...
 
void build_aggregate_barrier (void)
 Builds the aggregate barrier logic. More...
 
void build_var (void)
 Builds the variable that is actually incremented. More...
 
virtual std::string get_debug_info_ (void)
 Returns the type of the container along with name and any other useful information. More...
 
void init_noharm (void)
 Initialize the no harm eval settings. More...
 
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 false. More...
 
virtual bool is_true_ (void) const
 Polymorphic is true method which can be used to determine if all values in the container are true. More...
 
virtual void modify_ (void)
 Polymorphic modify method used by collection containers. More...
 

Private Attributes

CompiledExpression aggregate_barrier_
 Expression for aggregating barrier in one atomic operation. More...
 
ThreadSafeContextcontext_
 Variable context that we are modifying. More...
 
size_t id_
 id of this barrier in the barrier ring More...
 
EvalSettings no_harm
 Settings we'll use for all evaluations. More...
 
size_t participants_
 the number of participants in the barrier ring More...
 
VariableReference variable_
 Variable reference. More...
 
std::string variable_name_
 Holder for variable name to quickly refresh modified status. More...
 

Detailed Description

This class stores an integer within a variable context.

Definition at line 33 of file Barrier.h.

Member Typedef Documentation

trait that describes the value type

Definition at line 37 of file Barrier.h.

Constructor & Destructor Documentation

madara::knowledge::containers::Barrier::Barrier ( const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings ())

Default constructor.

Definition at line 9 of file Barrier.cpp.

madara::knowledge::containers::Barrier::Barrier ( const std::string &  name,
KnowledgeBase knowledge,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)

Constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
settingssettings for evaluating the vector

Definition at line 16 of file Barrier.cpp.

madara::knowledge::containers::Barrier::Barrier ( const std::string &  name,
Variables knowledge,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)

Constructor.

Parameters
namethe name of the map within the variable context
knowledgethe variable context
settingssettings to apply by default

Definition at line 28 of file Barrier.cpp.

madara::knowledge::containers::Barrier::Barrier ( const std::string &  name,
KnowledgeBase knowledge,
int  id,
int  participants,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)

Default constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
idthe id of the barrier in the barrier ring
participantsthe number of participants in the barrier ring
settingssettings for evaluating the vector

Definition at line 40 of file Barrier.cpp.

madara::knowledge::containers::Barrier::Barrier ( const std::string &  name,
Variables knowledge,
int  id,
int  participants,
const KnowledgeUpdateSettings settings = KnowledgeUpdateSettings () 
)

Default constructor.

Parameters
namename of the integer in the knowledge base
knowledgethe knowledge base that will contain the vector
idthe id of the barrier in the barrier ring
participantsthe number of participants in the barrier ring
settingssettings for evaluating the vector

Definition at line 54 of file Barrier.cpp.

madara::knowledge::containers::Barrier::Barrier ( const Barrier rhs)

Copy constructor.

Definition at line 69 of file Barrier.cpp.

madara::knowledge::containers::Barrier::~Barrier ( )

Destructor.

Definition at line 81 of file Barrier.cpp.

Member Function Documentation

type madara::knowledge::containers::Barrier::barrier_result ( void  ) const
inlineprivate

Checks if current barrier is successful.

Returns
0 if unsuccessful, otherwise it is successful

Definition at line 330 of file Barrier.h.

void madara::knowledge::containers::Barrier::build_aggregate_barrier ( void  )
private

Builds the aggregate barrier logic.

Definition at line 105 of file Barrier.cpp.

void madara::knowledge::containers::Barrier::build_var ( void  )
private

Builds the variable that is actually incremented.

Definition at line 154 of file Barrier.cpp.

madara::knowledge::containers::BaseContainer * madara::knowledge::containers::Barrier::clone ( void  ) const
virtual

Clones this container.

Returns
a deep copy of the container that must be managed by the user (i.e., you have to delete the return value)

Implements madara::knowledge::containers::BaseContainer.

Definition at line 445 of file Barrier.cpp.

std::string madara::knowledge::containers::Barrier::get_debug_info ( void  )

Returns the type of the container along with name and any other useful information.

The provided information should be useful for developers wishing to debug container operations, especially as it pertains to pending network operations (i.e., when used in conjunction with modify)

Returns
info in format {container}: {name}{ = value, if appropriate}

Definition at line 397 of file Barrier.cpp.

std::string madara::knowledge::containers::Barrier::get_debug_info_ ( void  )
privatevirtual

Returns the type of the container along with name and any other useful information.

The provided information should be useful for developers wishing to debug container operations, especially as it pertains to pending network operations (i.e., when used in conjunction with modify)

Returns
info in format {container}: {name}{ = value, if appropriate}

Implements madara::knowledge::containers::BaseContainer.

Definition at line 439 of file Barrier.cpp.

size_t madara::knowledge::containers::Barrier::get_id ( void  ) const

Returns the id of the barrier in the barrier ring.

Returns
the id of the barrier

Definition at line 197 of file Barrier.cpp.

std::string madara::knowledge::containers::BaseContainer::get_name ( void  ) const
inlineinherited

Returns the name of the container.

Returns
name of the container

Definition at line 5 of file BaseContainer.inl.

size_t madara::knowledge::containers::Barrier::get_participants ( void  ) const

Returns the number of participants in the barrier ring.

Returns
the number of participants barriering

Definition at line 204 of file Barrier.cpp.

type madara::knowledge::containers::Barrier::get_round ( void  ) const
inline

Returns the current barrier round.

Returns
the current barrier round number

Definition at line 129 of file Barrier.h.

madara::knowledge::KnowledgeUpdateSettings madara::knowledge::containers::BaseContainer::get_settings ( void  )
inherited

Gets the update settings for the container.

Returns
the current settings

Definition at line 37 of file BaseContainer.cpp.

void madara::knowledge::containers::Barrier::init_noharm ( void  )
private

Initialize the no harm eval settings.

Definition at line 186 of file Barrier.cpp.

bool madara::knowledge::containers::Barrier::is_done ( void  )

Wait for all other participants to reach your barrier round.

Returns
true if barrier round is finished. False otherwise.

Definition at line 345 of file Barrier.cpp.

bool madara::knowledge::containers::Barrier::is_false ( void  ) const

Determines if the barrier is false.

Returns
true if the barrier is false

Definition at line 515 of file Barrier.cpp.

bool madara::knowledge::containers::Barrier::is_false_ ( void  ) const
privatevirtual

Polymorphic is false method which can be used to determine if at least one value in the container is false.

Implements madara::knowledge::containers::BaseContainer.

Definition at line 528 of file Barrier.cpp.

bool madara::knowledge::containers::Barrier::is_true ( void  ) const

Determines if the barrier is true.

Returns
true if the barrier is true

Definition at line 494 of file Barrier.cpp.

bool madara::knowledge::containers::Barrier::is_true_ ( void  ) const
privatevirtual

Polymorphic is true method which can be used to determine if all values in the container are true.

Implements madara::knowledge::containers::BaseContainer.

Definition at line 522 of file Barrier.cpp.

void madara::knowledge::containers::Barrier::modify ( void  )

Mark the value as modified.

The barrier retains the same value but will resend its value as if it had been modified.

Definition at line 388 of file Barrier.cpp.

void madara::knowledge::containers::Barrier::modify_ ( void  )
privatevirtual

Polymorphic modify method used by collection containers.

This method calls the modify method for this class. We separate the faster version (modify) from this version (modify_) to allow users the opportunity to have a fastery version that does not use polymorphic functions (generally virtual functions are half as efficient as normal function calls)

Implements madara::knowledge::containers::BaseContainer.

Definition at line 433 of file Barrier.cpp.

bool madara::knowledge::containers::BaseContainer::modify_if_false ( BaseContainer conditional)
virtualinherited

Modifies the container if the argument is false.

Parameters
conditionalthe container that must be false to modify
Returns
true if the container was modified

Definition at line 64 of file BaseContainer.cpp.

bool madara::knowledge::containers::BaseContainer::modify_if_true ( BaseContainer conditional)
virtualinherited

Modifies the container if the argument is true.

Parameters
conditionalthe container that must be true to modify
Returns
true if the container was modified

Definition at line 44 of file BaseContainer.cpp.

void madara::knowledge::containers::Barrier::next ( void  )

Goes to the next barrier round.

Definition at line 334 of file Barrier.cpp.

bool madara::knowledge::containers::Barrier::operator!= ( const Barrier value) const

Checks for inequality.

Parameters
valuethe value to compare to
Returns
true if inequal, false otherwise
void madara::knowledge::containers::Barrier::operator= ( const Barrier rhs)

Assignment operator.

Parameters
rhsvalue to copy

Definition at line 87 of file Barrier.cpp.

madara::knowledge::containers::Barrier::type madara::knowledge::containers::Barrier::operator= ( type  value)

Sets the value of the variable.

Parameters
valuethe new value of the variable
Returns
the updated value (should be same as value param)

Definition at line 290 of file Barrier.cpp.

bool madara::knowledge::containers::Barrier::operator== ( const Barrier value) const

Checks for equality.

Parameters
valuethe value to compare to
Returns
true if equal, false otherwise
void madara::knowledge::containers::Barrier::resize ( size_t  id = 0,
size_t  participants = 1 
)

Resizes the barrier, usually when number of participants change.

Parameters
idthe id of this barrier in the barrier ring
participantsthe number of participants in barrier ring

Definition at line 274 of file Barrier.cpp.

void madara::knowledge::containers::Barrier::set ( type  value)

Sets the barrier to a specific round.

Returns
the barrier round number

Definition at line 379 of file Barrier.cpp.

void madara::knowledge::containers::Barrier::set_name ( const std::string &  var_name,
KnowledgeBase knowledge,
int  id,
int  participants 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in
idthe id of the barrier in the barrier ring
participantsthe number of participants in the barrier ring

Definition at line 211 of file Barrier.cpp.

void madara::knowledge::containers::Barrier::set_name ( const std::string &  var_name,
Variables knowledge,
int  id,
int  participants 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in
idthe id of the barrier in the barrier ring
participantsthe number of participants in the barrier ring

Definition at line 232 of file Barrier.cpp.

void madara::knowledge::containers::Barrier::set_name ( const std::string &  var_name,
ThreadSafeContext knowledge,
int  id,
int  participants 
)

Sets the variable name that this refers to.

Parameters
var_namethe name of the variable in the knowledge base
knowledgethe knowledge base the variable is housed in
idthe id of the barrier in the barrier ring
participantsthe number of participants in the barrier ring

Definition at line 253 of file Barrier.cpp.

void madara::knowledge::containers::Barrier::set_quality ( uint32_t  quality,
const KnowledgeReferenceSettings settings = KnowledgeReferenceSettings (false) 
)

Sets the quality of writing to the barrier variables.

Parameters
qualityquality of writing to this location
settingssettings for referring to knowledge variables

Definition at line 481 of file Barrier.cpp.

void madara::knowledge::containers::BaseContainer::set_settings ( const KnowledgeUpdateSettings settings)
inherited

Sets the update settings for the container.

Parameters
settingsthe new settings to use

Definition at line 28 of file BaseContainer.cpp.

double madara::knowledge::containers::Barrier::to_double ( void  ) const

Returns the barrier round number as a double.

Returns
the value as a double

Definition at line 451 of file Barrier.cpp.

madara::knowledge::KnowledgeRecord::Integer madara::knowledge::containers::Barrier::to_integer ( void  ) const

Returns the barrier round number as an integer (same as *)

Returns
the value as an integer

Definition at line 318 of file Barrier.cpp.

madara::knowledge::KnowledgeRecord madara::knowledge::containers::Barrier::to_record ( void  ) const

Returns the barrier round number as a knowledge::KnowledgeRecord.

This is useful for referencing clock and other record info.

Returns
the value as a knowledge::KnowledgeRecord

Definition at line 303 of file Barrier.cpp.

std::string madara::knowledge::containers::Barrier::to_string ( void  ) const

Returns the barrier round number as a string.

Returns
the value as a string

Definition at line 466 of file Barrier.cpp.

Member Data Documentation

CompiledExpression madara::knowledge::containers::Barrier::aggregate_barrier_
private

Expression for aggregating barrier in one atomic operation.

Definition at line 368 of file Barrier.h.

ThreadSafeContext* madara::knowledge::containers::Barrier::context_
mutableprivate

Variable context that we are modifying.

Definition at line 348 of file Barrier.h.

size_t madara::knowledge::containers::Barrier::id_
private

id of this barrier in the barrier ring

Definition at line 358 of file Barrier.h.

MADARA_LOCK_TYPE madara::knowledge::containers::BaseContainer::mutex_
mutableprotectedinherited

guard for access and changes

Mutex for local changes

Definition at line 141 of file BaseContainer.h.

std::string madara::knowledge::containers::BaseContainer::name_
protectedinherited

Prefix of variable.

Definition at line 151 of file BaseContainer.h.

EvalSettings madara::knowledge::containers::Barrier::no_harm
private

Settings we'll use for all evaluations.

Definition at line 373 of file Barrier.h.

size_t madara::knowledge::containers::Barrier::participants_
private

the number of participants in the barrier ring

Definition at line 363 of file Barrier.h.

KnowledgeUpdateSettings madara::knowledge::containers::BaseContainer::settings_
protectedinherited

Settings for modifications.

Definition at line 156 of file BaseContainer.h.

VariableReference madara::knowledge::containers::Barrier::variable_
private

Variable reference.

Definition at line 353 of file Barrier.h.

std::string madara::knowledge::containers::Barrier::variable_name_
private

Holder for variable name to quickly refresh modified status.

Definition at line 378 of file Barrier.h.


The documentation for this class was generated from the following files: