Fawkes API
Fawkes Development Version
|
#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< SyncPointCall > | get_wait_calls (WakeupType type=WAIT_FOR_ONE) const |
CircularBuffer< SyncPointCall > | get_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< SyncPointCall > | emit_calls_ |
A buffer of the most recent emit calls. More... | |
CircularBuffer< SyncPointCall > | wait_for_one_calls_ |
A buffer of the most recent wait calls of type WAIT_FOR_ONE. More... | |
CircularBuffer< SyncPointCall > | wait_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... | |
Mutex * | mutex_ |
Mutex used to protect all member variables. More... | |
Mutex * | mutex_next_wait_ |
Mutex used to allow lock_until_next_wait. More... | |
WaitCondition * | cond_next_wait_ |
WaitCondition used for lock_until_next_wait. More... | |
Mutex * | mutex_wait_for_one_ |
Mutex used for cond_wait_for_one_. More... | |
WaitCondition * | cond_wait_for_one_ |
WaitCondition which is used for wait_for_one() More... | |
Mutex * | mutex_wait_for_all_ |
Mutex used for cond_wait_for_all_. More... | |
WaitCondition * | cond_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... | |
MultiLogger * | logger_ |
Logger. More... | |
Friends | |
class | SyncPointManager |
allow Syncpoint Manager to edit More... | |
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.
Definition at line 49 of file syncpoint.h.
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 56 of file syncpoint.h.
fawkes::SyncPoint::SyncPoint | ( | std::string | identifier, |
MultiLogger * | logger, | ||
uint | max_waittime_sec = 0 , |
||
uint | max_waittime_nsec = 0 |
||
) |
Constructor.
identifier | The identifier of the SyncPoint. This must be in absolute path style, e.g. '/some/syncpoint'. |
logger | The logger to use for error messages. |
max_waittime_sec | the maximum number of seconds to wait until a timeout is triggered |
max_waittime_nsec | the maximum number of nanoseconds to wait until a timeout is triggered |
Definition at line 57 of file syncpoint.cpp.
|
protected |
Add a watcher to the watch list.
watcher | the new watcher |
Definition at line 506 of file syncpoint.cpp.
|
virtual |
send a signal to all waiting threads
Wake up all components which are waiting for this SyncPoint.
component | The identifier of the component emitting the SyncPoint |
Definition at line 148 of file syncpoint.cpp.
Referenced by emit(), fawkes::SyncPointAspect::post_loop(), and unregister_emitter().
|
protectedvirtual |
send a signal to all waiting threads
Wake up all components which are waiting for this SyncPoint.
component | The identifier of the component emitting the SyncPoint |
remove_from_pending | if 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_.
CircularBuffer< SyncPointCall > fawkes::SyncPoint::get_emit_calls | ( | ) | const |
Definition at line 552 of file syncpoint.cpp.
References emit_calls_, and mutex_.
multiset< string > fawkes::SyncPoint::get_emitters | ( | ) | const |
Definition at line 543 of file syncpoint.cpp.
string fawkes::SyncPoint::get_identifier | ( | ) | const |
Definition at line 105 of file syncpoint.cpp.
References identifier_.
Referenced by emit(), operator<(), operator==(), and wait().
CircularBuffer< SyncPointCall > fawkes::SyncPoint::get_wait_calls | ( | WakeupType | type = WAIT_FOR_ONE | ) | const |
type | the 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_.
std::set< std::string > fawkes::SyncPoint::get_watchers | ( | ) | const |
Definition at line 516 of file syncpoint.cpp.
bool fawkes::SyncPoint::is_emitter | ( | const std::string & | component | ) | const |
Check if the given component is an emitter.
component | The name of the component. |
Definition at line 482 of file syncpoint.cpp.
References mutex_.
bool fawkes::SyncPoint::is_watcher | ( | const std::string & | component | ) | const |
Check if the given component is a watch.
component | The name of the component. |
Definition at line 493 of file syncpoint.cpp.
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().
component | the 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().
bool fawkes::SyncPoint::operator< | ( | const SyncPoint & | other | ) | const |
LessThan Operator.
Compare two SyncPoints using their identifiers.
other | The other SyncPoint |
Definition at line 139 of file syncpoint.cpp.
References get_identifier(), and identifier_.
bool fawkes::SyncPoint::operator== | ( | const SyncPoint & | other | ) | const |
EqualOperator.
Two SyncPoints are considered equal iff they have the same identifier
other | The other SyncPoint |
Definition at line 116 of file syncpoint.cpp.
References get_identifier(), and identifier_.
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.
other | the string to compare |
Definition at line 128 of file syncpoint.cpp.
References identifier_.
|
virtual |
register as emitter
Register an emitter.
A thread can only emit the barrier if it has been registered.
component | The 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().
|
virtual |
Wait for all registered emitters for the given time.
component | The identifier of the calling component. |
wait_sec | number of seconds to wait |
wait_nsec | number of nanoseconds to wait additionally to wait_sec |
Definition at line 385 of file syncpoint.cpp.
References wait().
|
virtual |
wait for the sync point, but abort after given time
Wait for a single emitter for the given time.
component | The identifier of the calling component. |
wait_sec | number of seconds to wait |
wait_nsec | number of nanoseconds to wait additionally to wait_sec |
Definition at line 374 of file syncpoint.cpp.
References wait().
|
virtual |
unregister as emitter
Unregister an emitter.
This removes the component from the syncpoint, thus other components will not wait for it anymore.
component | The identifier of the component which is unregistered. |
emit_if_pending | if 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().
|
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.
component | the 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_.
|
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.
component | The identifier of the component waiting for the SyncPoint |
type | the 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_sec | number of seconds to wait for the SyncPoint |
wait_nsec | number of nanoseconds to wait for the SyncPoint |
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(), fawkes::SyncPointAspect::pre_loop(), reltime_wait_for_all(), reltime_wait_for_one(), wait_for_all(), and wait_for_one().
|
virtual |
Wait for all registered emitters.
component | The identifier of the calling component. |
Definition at line 363 of file syncpoint.cpp.
References wait().
|
virtual |
Wait for a single emitter.
component | The identifier of the calling component. |
Definition at line 354 of file syncpoint.cpp.
References wait().
bool fawkes::SyncPoint::watcher_is_waiting | ( | std::string | watcher, |
WakeupType | type | ||
) | const |
Check if the given waiter is currently waiting with the given type.
watcher | the string identifier of the watcher to check |
type | the type of call to check |
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_.
|
friend |
allow Syncpoint Manager to edit
Definition at line 104 of file syncpoint.h.
|
protected |
WaitCondition used for lock_until_next_wait.
Definition at line 135 of file syncpoint.h.
|
protected |
WaitCondition which is used for wait_for_all()
Definition at line 143 of file syncpoint.h.
|
protected |
WaitCondition which is used for wait_for_one()
Definition at line 139 of file syncpoint.h.
|
protected |
Time when this SyncPoint was created.
Definition at line 128 of file syncpoint.h.
|
protected |
A buffer of the most recent emit calls.
Definition at line 122 of file syncpoint.h.
Referenced by emit(), and get_emit_calls().
|
protected |
The unique identifier of the SyncPoint.
Definition at line 113 of file syncpoint.h.
Referenced by get_identifier(), operator<(), operator==(), and watcher_is_waiting().
|
protected |
|
protected |
|
protected |
|
protected |
Mutex used to protect all member variables.
Definition at line 131 of file syncpoint.h.
Referenced by add_watcher(), emit(), get_emit_calls(), get_wait_calls(), get_watchers(), is_emitter(), is_watcher(), lock_until_next_wait(), register_emitter(), unregister_emitter(), unwait(), and wait().
|
protected |
Mutex used to allow lock_until_next_wait.
Definition at line 133 of file syncpoint.h.
Referenced by emit(), lock_until_next_wait(), and wait().
|
protected |
Mutex used for cond_wait_for_all_.
Definition at line 141 of file syncpoint.h.
Referenced by emit(), wait(), and watcher_is_waiting().
|
protected |
Mutex used for cond_wait_for_one_.
Definition at line 137 of file syncpoint.h.
Referenced by emit(), wait(), and watcher_is_waiting().
|
protected |
A buffer of the most recent wait calls of type WAIT_FOR_ALL.
Definition at line 126 of file syncpoint.h.
Referenced by get_wait_calls(), and wait().
|
protected |
the component that started the wait-for-all timer
Definition at line 147 of file syncpoint.h.
|
protected |
true if the wait for all timer is running
Definition at line 145 of file syncpoint.h.
|
protected |
A buffer of the most recent wait calls of type WAIT_FOR_ONE.
Definition at line 124 of file syncpoint.h.
Referenced by get_wait_calls(), and wait().
|
protected |
Set of all components which use this SyncPoint.
Definition at line 115 of file syncpoint.h.
Referenced by add_watcher(), emit(), get_watchers(), is_watcher(), and wait().
|
protected |
Set of all components which are currently waiting on the barrier.
Definition at line 119 of file syncpoint.h.
Referenced by emit(), unwait(), wait(), and watcher_is_waiting().
|
protected |
Set of all components which are currently waiting for a single emitter.
Definition at line 117 of file syncpoint.h.
Referenced by emit(), unwait(), wait(), and watcher_is_waiting().