SIMLIB/C++ 3.09
Loading...
Searching...
No Matches
simlib3::Barrier Class Reference

synchronization tool for processes More...

#include <simlib.h>

Inheritance diagram for simlib3::Barrier:
Collaboration diagram for simlib3::Barrier:

Public Member Functions

 Barrier (unsigned N)
 constructor
 Barrier (const char *_name, unsigned N)
 constructor with name parameter
virtual ~Barrier ()
 destructor
void ChangeHeight (unsigned new_maxn)
 change size
unsigned Height () const
 barrier size
virtual void Enter (Entity *e)
 wait for barrier break TODO: remove/rename
virtual bool Wait ()
 wait for barrier break (Current)
virtual int Break ()
 activate all waiting entities
void Clear ()
 initialization
virtual void Output () const override
 print status
Public Member Functions inherited from simlib3::SimObject
bool TestAndSetFlag (bool new_value, unsigned n)
 internal method for flag manipulation is used for algebraic loop checking in continuous blocks
 SimObject ()
 constructor
virtual ~SimObject ()
 virtual destructor
void * operator new (size_t size)
 allocate object, set _flags
void operator delete (void *ptr)
 deallocate object
void * operator new[] (size_t size)=delete
void operator delete[] (void *ptr)=delete
bool isAllocated () const
virtual std::string Name () const
 get object name
bool HasName () const
void SetName (const std::string &name)
 assign the name

Protected Member Functions

void Init ()
 initialization

Protected Attributes

Entity ** waiting
 array of waiting entities (fixed size)
unsigned n
 current number of waiting entities
unsigned maxn
 barrier height/size
Protected Attributes inherited from simlib3::SimObject
unsigned _flags
 bool flags for internal use (TODO bitfield?)

Additional Inherited Members

Public Types inherited from simlib3::SimObject
enum  _Flags { _CLEAR_ALL_FLAGS = 0 , _ALLOCATED_FLAG = 1<<0 , _EVAL_FLAG = 1<<1 , _HAS_NAME_FLAG = 1<<2 }

Detailed Description

synchronization tool for processes

Definition at line 1781 of file simlib.h.

Constructor & Destructor Documentation

◆ Barrier() [1/2]

simlib3::Barrier::Barrier ( unsigned N)
explicit

constructor

Definition at line 32 of file barrier.cc.

References Dprintf, Init(), maxn, n, and waiting.

◆ Barrier() [2/2]

simlib3::Barrier::Barrier ( const char * _name,
unsigned N )

constructor with name parameter

Definition at line 42 of file barrier.cc.

References Dprintf, Init(), maxn, n, simlib3::SimObject::SetName(), and waiting.

◆ ~Barrier()

simlib3::Barrier::~Barrier ( )
virtual

destructor

Definition at line 54 of file barrier.cc.

References Dprintf, simlib3::SimObject::Name(), and waiting.

Member Function Documentation

◆ Break()

int simlib3::Barrier::Break ( )
virtual

activate all waiting entities

Activate all processes waiting on the barrier returns: number of activated entities Warning: can be called only by process not already waiting on barrier.

Definition at line 97 of file barrier.cc.

References simlib3::Entity::Activate(), n, and waiting.

Referenced by Enter(), and Wait().

◆ ChangeHeight()

void simlib3::Barrier::ChangeHeight ( unsigned new_maxn)

change size

Change the height of barrier.

Definition at line 125 of file barrier.cc.

References Dprintf, simlib3::Error(), maxn, n, simlib3::SimObject::Name(), and waiting.

◆ Clear()

void simlib3::Barrier::Clear ( )

initialization

Barrier re-initializtion TODO: what to do with currently waiting passive processes?

Definition at line 144 of file barrier.cc.

References Dprintf, maxn, n, simlib3::SimObject::Name(), and waiting.

Referenced by Init().

◆ Enter()

void simlib3::Barrier::Enter ( Entity * e)
virtual

wait for barrier break TODO: remove/rename

enter the barrier

Definition at line 62 of file barrier.cc.

References simlib3::Entity::Activate(), Break(), simlib3::Current, Dprintf, maxn, n, simlib3::SimObject::Name(), simlib3::Entity::Passivate(), and waiting.

◆ Height()

unsigned simlib3::Barrier::Height ( ) const
inline

barrier size

Definition at line 1792 of file simlib.h.

References maxn.

◆ Init()

void simlib3::Barrier::Init ( )
protected

initialization

Barrier initializtion.

Definition at line 113 of file barrier.cc.

References Clear(), Dprintf, simlib3::Error(), maxn, simlib3::SimObject::Name(), and waiting.

Referenced by Barrier(), and Barrier().

◆ Output()

void simlib3::Barrier::Output ( ) const
overridevirtual

print status

Print barrier status.

Reimplemented from simlib3::SimObject.

Definition at line 154 of file barrier.cc.

References maxn, simlib3::SimObject::Name(), simlib3::Print(), and waiting.

◆ Wait()

bool simlib3::Barrier::Wait ( )
virtual

wait for barrier break (Current)

Wait or break the barrier returns: true for last process breaking the barrier, else false.

Definition at line 78 of file barrier.cc.

References simlib3::Entity::Activate(), Break(), simlib3::Current, Dprintf, maxn, n, simlib3::SimObject::Name(), simlib3::Entity::Passivate(), simlib3::Time, and waiting.

Member Data Documentation

◆ maxn

unsigned simlib3::Barrier::maxn
protected

barrier height/size

Definition at line 1785 of file simlib.h.

Referenced by Barrier(), Barrier(), ChangeHeight(), Clear(), Enter(), Height(), Init(), Output(), and Wait().

◆ n

unsigned simlib3::Barrier::n
protected

current number of waiting entities

Definition at line 1784 of file simlib.h.

Referenced by Barrier(), Barrier(), Break(), ChangeHeight(), Clear(), Enter(), and Wait().

◆ waiting

Entity** simlib3::Barrier::waiting
protected

array of waiting entities (fixed size)

Definition at line 1783 of file simlib.h.

Referenced by Barrier(), Barrier(), Break(), ChangeHeight(), Clear(), Enter(), Init(), Output(), Wait(), and ~Barrier().


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