Fawkes API  Fawkes Development Version
fawkes::SyncPoint Class Reference

#include <>>

Public Types

enum  WakeupType { WAIT_FOR_ONE, WAIT_FOR_ALL, NONE }
 Type to define when a thread wakes up after waiting for a SyncPoint. More...
 

Public Member Functions

 SyncPoint (std::string identifier, MultiLogger *logger, uint max_waittime_sec=0, uint max_waittime_nsec=0)
 Constructor. More...
 
virtual void emit (const std::string &component)
 send a signal to all waiting threads More...
 
virtual void wait (const std::string &component, WakeupType=WAIT_FOR_ONE, uint wait_sec=0, uint wait_nsec=0)
 wait for the sync point to be emitted by any other component More...
 
virtual void unwait (const std::string &component)
 abort waiting More...
 
virtual void wait_for_one (const std::string &component)
 Wait for a single emitter. More...
 
virtual void wait_for_all (const std::string &component)
 Wait for all registered emitters. More...
 
virtual void reltime_wait_for_one (const std::string &component, uint wait_sec, uint wait_nsec)
 wait for the sync point, but abort after given time More...
 
virtual void reltime_wait_for_all (const std::string &component, uint wait_sec, uint wait_nsec)
 Wait for all registered emitters for the given time. More...
 
virtual void register_emitter (const std::string &component)
 register as emitter More...
 
virtual void unregister_emitter (const std::string &component, bool emit_if_pending=true)
 unregister as emitter More...
 
bool is_emitter (const std::string &component) const
 Check if the given component is an emitter. More...
 
bool is_watcher (const std::string &component) const
 Check if the given component is a watch. More...
 
void lock_until_next_wait (const std::string &component)
 Lock the SyncPoint for emitters until the specified component does the next wait() call. More...
 
std::string get_identifier () const
 
bool operator== (const SyncPoint &other) const
 EqualOperator. More...
 
bool operator== (const std::string &other) const
 EqualOperator. More...
 
bool operator< (const SyncPoint &other) const
 LessThan Operator. More...
 
std::set< std::string > get_watchers () const
 
std::multiset< std::string > get_emitters () const
 
CircularBuffer< SyncPointCallget_wait_calls (WakeupType type=WAIT_FOR_ONE) const
 
CircularBuffer< SyncPointCallget_emit_calls () const
 
bool watcher_is_waiting (std::string watcher, WakeupType type) const
 Check if the given waiter is currently waiting with the given type. More...
 

Protected Member Functions

std::pair< std::set< std::string >::iterator, bool > add_watcher (std::string watcher)
 Add a watcher to the watch list. More...
 
virtual void emit (const std::string &component, bool remove_from_pending)
 send a signal to all waiting threads More...
 

Protected Attributes

const std::string identifier_
 The unique identifier of the SyncPoint. More...
 
std::set< std::string > watchers_
 Set of all components which use this SyncPoint. More...
 
std::set< std::string > watchers_wait_for_one_
 Set of all components which are currently waiting for a single emitter. More...
 
std::set< std::string > watchers_wait_for_all_
 Set of all components which are currently waiting on the barrier. More...
 
CircularBuffer< SyncPointCallemit_calls_
 A buffer of the most recent emit calls. More...
 
CircularBuffer< SyncPointCallwait_for_one_calls_
 A buffer of the most recent wait calls of type WAIT_FOR_ONE. More...
 
CircularBuffer< SyncPointCallwait_for_all_calls_
 A buffer of the most recent wait calls of type WAIT_FOR_ALL. More...
 
const Time creation_time_
 Time when this SyncPoint was created. More...
 
Mutexmutex_
 Mutex used to protect all member variables. More...
 
Mutexmutex_next_wait_
 Mutex used to allow lock_until_next_wait. More...
 
WaitConditioncond_next_wait_
 WaitCondition used for lock_until_next_wait. More...
 
Mutexmutex_wait_for_one_
 Mutex used for cond_wait_for_one_. More...
 
WaitConditioncond_wait_for_one_
 WaitCondition which is used for wait_for_one() More...
 
Mutexmutex_wait_for_all_
 Mutex used for cond_wait_for_all_. More...
 
WaitConditioncond_wait_for_all_
 WaitCondition which is used for wait_for_all() More...
 
bool wait_for_all_timer_running_
 true if the wait for all timer is running More...
 
std::string wait_for_all_timer_owner_
 the component that started the wait-for-all timer More...
 
uint max_waittime_sec_
 maximum waiting time in secs More...
 
uint max_waittime_nsec_
 maximum waiting time in nsecs More...
 
MultiLoggerlogger_
 Logger. More...
 

Friends

class SyncPointManager
 allow Syncpoint Manager to edit More...
 

Detailed Description

The SyncPoint class. This class is used for dynamic synchronization of threads which depend on each other, e.g. threads which are part of a processing chain.

As an example, thread E generates data which is needed by thread W. Therefore, both threads share a SyncPoint. Thread W wait()s for the SyncPoint to be emitted. Once thread E is done, it emit()s the SyncPoint, which wakes up thread W.

Author
Till Hofmann
See also
SyncPointManager

Definition at line 55 of file syncpoint.h.

Member Enumeration Documentation

◆ WakeupType

Type to define when a thread wakes up after waiting for a SyncPoint.

A thread can be either wake up if ANY other thread emits the SyncPoint, or if ALL registered threads emit the SyncPoint.

Definition at line 62 of file syncpoint.h.

Constructor & Destructor Documentation

◆ SyncPoint()

fawkes::SyncPoint::SyncPoint ( std::string  identifier,
MultiLogger logger,
uint  max_waittime_sec = 0,
uint  max_waittime_nsec = 0 
)

Constructor.

Parameters
identifierThe identifier of the SyncPoint. This must be in absolute path style, e.g. '/some/syncpoint'.
loggerThe logger to use for error messages.
max_waittime_secthe maximum number of seconds to wait until a timeout is triggered
max_waittime_nsecthe maximum number of nanoseconds to wait until a timeout is triggered

Definition at line 57 of file syncpoint.cpp.

Member Function Documentation

◆ add_watcher()

pair< set< string >::iterator, bool > fawkes::SyncPoint::add_watcher ( std::string  watcher)
protected

Add a watcher to the watch list.

Parameters
watcherthe new watcher
Returns
A pair, of which the first element is an iterator that points to the possibly inserted element, and the second is a bool that is true if the element was actually inserted.

Definition at line 506 of file syncpoint.cpp.

References mutex_, and watchers_.

◆ emit() [1/2]

void fawkes::SyncPoint::emit ( const std::string &  component)
virtual

send a signal to all waiting threads

Wake up all components which are waiting for this SyncPoint.

Parameters
componentThe identifier of the component emitting the SyncPoint

Definition at line 148 of file syncpoint.cpp.

Referenced by emit(), fawkes::SyncPointAspect::pre_loop(), and unregister_emitter().

◆ emit() [2/2]

void fawkes::SyncPoint::emit ( const std::string &  component,
bool  remove_from_pending 
)
protectedvirtual

send a signal to all waiting threads

Wake up all components which are waiting for this SyncPoint.

Parameters
componentThe identifier of the component emitting the SyncPoint
remove_from_pendingif set to true, the component will be removed from the pending emitters for this syncpoint

Definition at line 159 of file syncpoint.cpp.

References cond_next_wait_, cond_wait_for_all_, cond_wait_for_one_, emit(), emit_calls_, get_identifier(), fawkes::Mutex::lock(), mutex_, mutex_next_wait_, mutex_wait_for_all_, mutex_wait_for_one_, fawkes::Mutex::unlock(), fawkes::WaitCondition::wait(), fawkes::WaitCondition::wake_all(), watchers_, watchers_wait_for_all_, and watchers_wait_for_one_.

◆ get_emit_calls()

CircularBuffer< SyncPointCall > fawkes::SyncPoint::get_emit_calls ( ) const
Returns
a copy of the emit call buffer

Definition at line 552 of file syncpoint.cpp.

References emit_calls_, and mutex_.

◆ get_emitters()

multiset< string > fawkes::SyncPoint::get_emitters ( ) const
Returns
a copy of the set of registered emitters

Definition at line 543 of file syncpoint.cpp.

◆ get_identifier()

string fawkes::SyncPoint::get_identifier ( ) const
Returns
the identifier of the SyncPoint

Definition at line 105 of file syncpoint.cpp.

References identifier_.

Referenced by emit(), operator<(), operator==(), and wait().

◆ get_wait_calls()

CircularBuffer< SyncPointCall > fawkes::SyncPoint::get_wait_calls ( WakeupType  type = WAIT_FOR_ONE) const
Returns
a copy of the wait call buffer with the given type
Parameters
typethe type of the wait call buffer

Definition at line 527 of file syncpoint.cpp.

References mutex_, wait_for_all_calls_, and wait_for_one_calls_.

◆ get_watchers()

std::set< std::string > fawkes::SyncPoint::get_watchers ( ) const
Returns
all watchers of the SyncPoint

Definition at line 516 of file syncpoint.cpp.

References mutex_, and watchers_.

◆ is_emitter()

bool fawkes::SyncPoint::is_emitter ( const std::string &  component) const

Check if the given component is an emitter.

Parameters
componentThe name of the component.
Returns
True iff the given component is an emitter of this syncpoint.

Definition at line 482 of file syncpoint.cpp.

References mutex_.

◆ is_watcher()

bool fawkes::SyncPoint::is_watcher ( const std::string &  component) const

Check if the given component is a watch.

Parameters
componentThe name of the component.
Returns
True iff the given component is a watcher.

Definition at line 493 of file syncpoint.cpp.

References mutex_, and watchers_.

◆ lock_until_next_wait()

void fawkes::SyncPoint::lock_until_next_wait ( const std::string &  component)

Lock the SyncPoint for emitters until the specified component does the next wait() call.

This forces an emitter of this SyncPoint to wait during the emit until the waiter calls wait(). This is useful if you want to guarantee that the waiter does not call wait() immediately after the emitter has called emit().

Parameters
componentthe component locking the SyncPoint

Definition at line 416 of file syncpoint.cpp.

References fawkes::Mutex::lock(), fawkes::MultiLogger::log_warn(), logger_, mutex_, mutex_next_wait_, and fawkes::Mutex::unlock().

◆ operator<()

bool fawkes::SyncPoint::operator< ( const SyncPoint other) const

LessThan Operator.

Compare two SyncPoints using their identifiers.

Parameters
otherThe other SyncPoint
Returns
true if strcmp returns a value < 0 for the identifiers

Definition at line 139 of file syncpoint.cpp.

References get_identifier(), and identifier_.

◆ operator==() [1/2]

bool fawkes::SyncPoint::operator== ( const std::string &  other) const

EqualOperator.

A SyncPoint is equal to a given string iff the string is equal to the SyncPoint's identifier.

Parameters
otherthe string to compare
Returns
true if the identifier of the SyncPoint matches the given string

Definition at line 128 of file syncpoint.cpp.

References identifier_.

◆ operator==() [2/2]

bool fawkes::SyncPoint::operator== ( const SyncPoint other) const

EqualOperator.

Two SyncPoints are considered equal iff they have the same identifier

Parameters
otherThe other SyncPoint
Returns
true if the identifiers of the SyncPoints are equal

Definition at line 116 of file syncpoint.cpp.

References get_identifier(), and identifier_.

◆ register_emitter()

void fawkes::SyncPoint::register_emitter ( const std::string &  component)
virtual

register as emitter

Register an emitter.

A thread can only emit the barrier if it has been registered.

Parameters
componentThe identifier of the registering component.

Definition at line 437 of file syncpoint.cpp.

References mutex_, and register_emitter().

Referenced by Emitter::Emitter(), fawkes::SyncPointAspect::init_SyncPointAspect(), and register_emitter().

◆ reltime_wait_for_all()

void fawkes::SyncPoint::reltime_wait_for_all ( const std::string &  component,
uint  wait_sec,
uint  wait_nsec 
)
virtual

Wait for all registered emitters for the given time.

Parameters
componentThe identifier of the calling component.
wait_secnumber of seconds to wait
wait_nsecnumber of nanoseconds to wait additionally to wait_sec

Definition at line 385 of file syncpoint.cpp.

References wait().

◆ reltime_wait_for_one()

void fawkes::SyncPoint::reltime_wait_for_one ( const std::string &  component,
uint  wait_sec,
uint  wait_nsec 
)
virtual

wait for the sync point, but abort after given time

Wait for a single emitter for the given time.

Parameters
componentThe identifier of the calling component.
wait_secnumber of seconds to wait
wait_nsecnumber of nanoseconds to wait additionally to wait_sec

Definition at line 374 of file syncpoint.cpp.

References wait().

◆ unregister_emitter()

void fawkes::SyncPoint::unregister_emitter ( const std::string &  component,
bool  emit_if_pending = true 
)
virtual

unregister as emitter

Unregister an emitter.

This removes the component from the syncpoint, thus other components will not wait for it anymore.

Parameters
componentThe identifier of the component which is unregistered.
emit_if_pendingif this is set to true and the component is a pending emitter, emit the syncpoint before releasing it.

Definition at line 454 of file syncpoint.cpp.

References emit(), mutex_, fawkes::MutexLocker::relock(), fawkes::MutexLocker::unlock(), and unregister_emitter().

Referenced by fawkes::SyncPointAspect::finalize_SyncPointAspect(), and unregister_emitter().

◆ unwait()

void fawkes::SyncPoint::unwait ( const std::string &  component)
virtual

abort waiting

Do not wait for the SyncPoint any longer.

Removes the component from the list of waiters. If the given component is not waiting, do nothing.

Parameters
componentthe component to remove from the waiters

Definition at line 396 of file syncpoint.cpp.

References mutex_, wait_for_all_timer_owner_, wait_for_all_timer_running_, watchers_wait_for_all_, and watchers_wait_for_one_.

◆ wait()

void fawkes::SyncPoint::wait ( const std::string &  component,
WakeupType  type = WAIT_FOR_ONE,
uint  wait_sec = 0,
uint  wait_nsec = 0 
)
virtual

wait for the sync point to be emitted by any other component

Wait until SyncPoint is emitted.

Either wait until a single emitter has emitted the SyncPoint, or wait until all registered emitters have emitted the SyncPoint. If wait_sec != 0 or wait_nsec !=0, then only wait for wait_sec + wait_nsec*10^-9 seconds and set the SyncPoint's maximum waiting time to the specified time (i.e., on any subsequent wait calls, wait for the specified time until a timeout is triggered). If the maximal wait time has been exceeded, a warning is shown and the SyncPoint is released. If the WakeupType is WAIT_FOR_ALL, then the time limit is only used if there is currently no other component waiting in WAIT_FOR_ALL mode. If there is already a component waiting, that component's wait_time is used to compute the timeout. This ensures that in case a timeout occurs, all waiting components in WAIT_FOR_ALL mode are released simultaneously. Components in WAIT_FOR_ONE mode are treated separately and have their own timeouts.

Parameters
componentThe identifier of the component waiting for the SyncPoint
typethe wakeup type. If this is set to WAIT_FOR_ONE, wait returns when a single emitter has emitted the SyncPoint. If set to WAIT_FOR_ALL, wait until all registered emitters have emitted the SyncPoint.
wait_secnumber of seconds to wait for the SyncPoint
wait_nsecnumber of nanoseconds to wait for the SyncPoint
See also
SyncPoint::WakeupType

Definition at line 239 of file syncpoint.cpp.

References cond_next_wait_, cond_wait_for_all_, cond_wait_for_one_, get_identifier(), fawkes::Mutex::lock(), max_waittime_nsec_, max_waittime_sec_, mutex_, mutex_next_wait_, mutex_wait_for_all_, mutex_wait_for_one_, fawkes::CircularBuffer< Type >::push_back(), fawkes::MutexLocker::relock(), fawkes::WaitCondition::reltimed_wait(), fawkes::MutexLocker::unlock(), fawkes::Mutex::unlock(), fawkes::WaitCondition::wait(), wait_for_all_calls_, wait_for_all_timer_owner_, wait_for_all_timer_running_, wait_for_one_calls_, fawkes::WaitCondition::wake_all(), watchers_, watchers_wait_for_all_, and watchers_wait_for_one_.

Referenced by fawkes::FawkesTimingThread::loop(), reltime_wait_for_all(), reltime_wait_for_one(), wait_for_all(), and wait_for_one().

◆ wait_for_all()

void fawkes::SyncPoint::wait_for_all ( const std::string &  component)
virtual

Wait for all registered emitters.

Parameters
componentThe identifier of the calling component.

Definition at line 363 of file syncpoint.cpp.

References wait().

◆ wait_for_one()

void fawkes::SyncPoint::wait_for_one ( const std::string &  component)
virtual

Wait for a single emitter.

Parameters
componentThe identifier of the calling component.

Definition at line 354 of file syncpoint.cpp.

References wait().

◆ watcher_is_waiting()

bool fawkes::SyncPoint::watcher_is_waiting ( std::string  watcher,
WakeupType  type 
) const

Check if the given waiter is currently waiting with the given type.

Parameters
watcherthe string identifier of the watcher to check
typethe type of call to check
Returns
true if the waiter is currently waiting

Definition at line 565 of file syncpoint.cpp.

References identifier_, mutex_wait_for_all_, mutex_wait_for_one_, watchers_wait_for_all_, and watchers_wait_for_one_.

Friends And Related Function Documentation

◆ SyncPointManager

friend class SyncPointManager
friend

allow Syncpoint Manager to edit

Definition at line 110 of file syncpoint.h.

Member Data Documentation

◆ cond_next_wait_

WaitCondition* fawkes::SyncPoint::cond_next_wait_
protected

WaitCondition used for lock_until_next_wait.

Definition at line 141 of file syncpoint.h.

Referenced by emit(), and wait().

◆ cond_wait_for_all_

WaitCondition* fawkes::SyncPoint::cond_wait_for_all_
protected

WaitCondition which is used for wait_for_all()

Definition at line 149 of file syncpoint.h.

Referenced by emit(), and wait().

◆ cond_wait_for_one_

WaitCondition* fawkes::SyncPoint::cond_wait_for_one_
protected

WaitCondition which is used for wait_for_one()

Definition at line 145 of file syncpoint.h.

Referenced by emit(), and wait().

◆ creation_time_

const Time fawkes::SyncPoint::creation_time_
protected

Time when this SyncPoint was created.

Definition at line 134 of file syncpoint.h.

◆ emit_calls_

CircularBuffer<SyncPointCall> fawkes::SyncPoint::emit_calls_
protected

A buffer of the most recent emit calls.

Definition at line 128 of file syncpoint.h.

Referenced by emit(), and get_emit_calls().

◆ identifier_

const std::string fawkes::SyncPoint::identifier_
protected

The unique identifier of the SyncPoint.

Definition at line 119 of file syncpoint.h.

Referenced by get_identifier(), operator<(), operator==(), and watcher_is_waiting().

◆ logger_

MultiLogger* fawkes::SyncPoint::logger_
protected

Logger.

Definition at line 160 of file syncpoint.h.

Referenced by lock_until_next_wait().

◆ max_waittime_nsec_

uint fawkes::SyncPoint::max_waittime_nsec_
protected

maximum waiting time in nsecs

Definition at line 157 of file syncpoint.h.

Referenced by wait().

◆ max_waittime_sec_

uint fawkes::SyncPoint::max_waittime_sec_
protected

maximum waiting time in secs

Definition at line 155 of file syncpoint.h.

Referenced by wait().

◆ mutex_

Mutex* fawkes::SyncPoint::mutex_
protected

◆ mutex_next_wait_

Mutex* fawkes::SyncPoint::mutex_next_wait_
protected

Mutex used to allow lock_until_next_wait.

Definition at line 139 of file syncpoint.h.

Referenced by emit(), lock_until_next_wait(), and wait().

◆ mutex_wait_for_all_

Mutex* fawkes::SyncPoint::mutex_wait_for_all_
protected

Mutex used for cond_wait_for_all_.

Definition at line 147 of file syncpoint.h.

Referenced by emit(), wait(), and watcher_is_waiting().

◆ mutex_wait_for_one_

Mutex* fawkes::SyncPoint::mutex_wait_for_one_
protected

Mutex used for cond_wait_for_one_.

Definition at line 143 of file syncpoint.h.

Referenced by emit(), wait(), and watcher_is_waiting().

◆ wait_for_all_calls_

CircularBuffer<SyncPointCall> fawkes::SyncPoint::wait_for_all_calls_
protected

A buffer of the most recent wait calls of type WAIT_FOR_ALL.

Definition at line 132 of file syncpoint.h.

Referenced by get_wait_calls(), and wait().

◆ wait_for_all_timer_owner_

std::string fawkes::SyncPoint::wait_for_all_timer_owner_
protected

the component that started the wait-for-all timer

Definition at line 153 of file syncpoint.h.

Referenced by unwait(), and wait().

◆ wait_for_all_timer_running_

bool fawkes::SyncPoint::wait_for_all_timer_running_
protected

true if the wait for all timer is running

Definition at line 151 of file syncpoint.h.

Referenced by unwait(), and wait().

◆ wait_for_one_calls_

CircularBuffer<SyncPointCall> fawkes::SyncPoint::wait_for_one_calls_
protected

A buffer of the most recent wait calls of type WAIT_FOR_ONE.

Definition at line 130 of file syncpoint.h.

Referenced by get_wait_calls(), and wait().

◆ watchers_

std::set<std::string> fawkes::SyncPoint::watchers_
protected

Set of all components which use this SyncPoint.

Definition at line 121 of file syncpoint.h.

Referenced by add_watcher(), emit(), get_watchers(), is_watcher(), and wait().

◆ watchers_wait_for_all_

std::set<std::string> fawkes::SyncPoint::watchers_wait_for_all_
protected

Set of all components which are currently waiting on the barrier.

Definition at line 125 of file syncpoint.h.

Referenced by emit(), unwait(), wait(), and watcher_is_waiting().

◆ watchers_wait_for_one_

std::set<std::string> fawkes::SyncPoint::watchers_wait_for_one_
protected

Set of all components which are currently waiting for a single emitter.

Definition at line 123 of file syncpoint.h.

Referenced by emit(), unwait(), wait(), and watcher_is_waiting().


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