SIMLIB/C++  3.07
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
simlib3::Barrier Class Reference

synchronization tool for processes More...

#include <simlib.h>

Inheritance diagram for simlib3::Barrier:
Inheritance graph
[legend]
Collaboration diagram for simlib3::Barrier:
Collaboration graph
[legend]

Public Member Functions

 Barrier (unsigned N)
 constructor More...
 
 Barrier (const char *_name, unsigned N)
 constructor with name parameter More...
 
virtual ~Barrier ()
 destructor More...
 
void ChangeHeight (unsigned new_maxn)
 change size More...
 
unsigned Height () const
 barrier size More...
 
virtual void Enter (Entity *e)
 wait for barrier break TODO: remove/rename More...
 
virtual bool Wait ()
 wait for barrier break (Current) More...
 
virtual int Break ()
 activate all waiting entities More...
 
void Clear ()
 initialization More...
 
virtual void Output () const override
 print status More...
 
- 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 More...
 
 SimObject ()
 constructor More...
 
virtual ~SimObject ()
 virtual destructor More...
 
void * operator new (size_t size)
 allocate object, set _flags More...
 
void operator delete (void *ptr)
 deallocate object More...
 
void * operator new[] (size_t size)=delete
 
void operator delete[] (void *ptr)=delete
 
bool isAllocated () const
 
virtual std::string Name () const
 get object name More...
 
bool HasName () const
 
void SetName (const std::string &name)
 assign the name More...
 

Protected Member Functions

void Init ()
 initialization More...
 

Protected Attributes

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

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 1776 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, and Init().

◆ 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(), and simlib3::SimObject::SetName().

◆ ~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 1787 of file simlib.h.

References simlib3::SQS::Clear(), and simlib3::SimObject::Output().

◆ 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().

◆ 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 1780 of file simlib.h.

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

◆ n

unsigned simlib3::Barrier::n
protected

current number of waiting entities

Definition at line 1779 of file simlib.h.

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

◆ waiting

Entity** simlib3::Barrier::waiting
protected

array of waiting entities (fixed size)

Definition at line 1778 of file simlib.h.

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


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