22#ifndef _SYNCPOINT_SYNCPOINT_H_
23#define _SYNCPOINT_SYNCPOINT_H_
25#include <core/threading/mutex.h>
26#include <core/threading/wait_condition.h>
27#include <core/utils/circular_buffer.h>
28#include <core/utils/refptr.h>
29#include <interface/interface.h>
30#include <logging/multi.h>
31#include <syncpoint/syncpoint_call.h>
32#include <utils/time/time.h>
40class SyncPointManager;
56 typedef enum { WAIT_FOR_ONE, WAIT_FOR_ALL, NONE }
WakeupType;
60 uint max_waittime_sec = 0,
61 uint max_waittime_nsec = 0);
65 virtual void emit(
const std::string &component);
68 virtual void wait(
const std::string &component,
73 virtual void unwait(
const std::string &component);
84 virtual void unregister_emitter(
const std::string &component,
bool emit_if_pending =
true);
85 bool is_emitter(
const std::string &component)
const;
86 bool is_watcher(
const std::string &component)
const;
92 bool operator==(
const std::string &other)
const;
107 std::pair<std::set<std::string>::iterator,
bool>
add_watcher(std::string watcher);
109 virtual void emit(
const std::string &component,
bool remove_from_pending);
157 void reset_emitters();
158 bool is_pending(std::string component);
159 void handle_default(std::string component,
WakeupType type);
171 std::multiset<std::string> emitters_;
172 std::multiset<std::string> pending_emitters_;
174 std::set<std::string> bad_components_;
176 std::string emit_locker_;
178 Time last_emitter_reset_;
Circular buffer with a fixed size.
Log through multiple loggers.
Mutex mutual exclusion lock.
This class gives access to SyncPoints.
Compare sets of syncpoints.
bool operator()(const RefPtr< SyncPoint > sp1, const RefPtr< SyncPoint > sp2) const
LessThan Operator to use for the manager's SyncPoint set Since we store RefPtrs to SyncPoints we have...
bool operator<(const SyncPoint &other) const
LessThan Operator.
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
CircularBuffer< SyncPointCall > get_wait_calls(WakeupType type=WAIT_FOR_ONE) const
virtual void wait_for_one(const std::string &component)
Wait for a single emitter.
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
std::multiset< std::string > get_emitters() const
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.
std::set< std::string > watchers_wait_for_one_
Set of all components which are currently waiting for a single emitter.
bool wait_for_all_timer_running_
true if the wait for all timer is running
virtual void unwait(const std::string &component)
abort waiting
CircularBuffer< SyncPointCall > wait_for_all_calls_
A buffer of the most recent wait calls of type WAIT_FOR_ALL.
Mutex * mutex_wait_for_one_
Mutex used for cond_wait_for_one_.
WaitCondition * cond_wait_for_one_
WaitCondition which is used for wait_for_one()
virtual void unregister_emitter(const std::string &component, bool emit_if_pending=true)
unregister as emitter
uint max_waittime_sec_
maximum waiting time in secs
std::string wait_for_all_timer_owner_
the component that started the wait-for-all timer
Mutex * mutex_next_wait_
Mutex used to allow lock_until_next_wait.
uint max_waittime_nsec_
maximum waiting time in nsecs
const Time creation_time_
Time when this SyncPoint was created.
Mutex * mutex_wait_for_all_
Mutex used for cond_wait_for_all_.
std::set< std::string > get_watchers() const
std::set< std::string > watchers_wait_for_all_
Set of all components which are currently waiting on the barrier.
bool is_emitter(const std::string &component) const
Check if the given component is an emitter.
std::pair< std::set< std::string >::iterator, bool > add_watcher(std::string watcher)
Add a watcher to the watch list.
virtual void register_emitter(const std::string &component)
register as emitter
bool watcher_is_waiting(std::string watcher, WakeupType type) const
Check if the given waiter is currently waiting with the given type.
virtual void emit(const std::string &component)
send a signal to all waiting threads
WaitCondition * cond_next_wait_
WaitCondition used for lock_until_next_wait.
MultiLogger * logger_
Logger.
CircularBuffer< SyncPointCall > get_emit_calls() const
SyncPoint(std::string identifier, MultiLogger *logger, uint max_waittime_sec=0, uint max_waittime_nsec=0)
Constructor.
void lock_until_next_wait(const std::string &component)
Lock the SyncPoint for emitters until the specified component does the next wait() call.
std::set< std::string > watchers_
Set of all components which use this SyncPoint.
CircularBuffer< SyncPointCall > emit_calls_
A buffer of the most recent emit calls.
CircularBuffer< SyncPointCall > wait_for_one_calls_
A buffer of the most recent wait calls of type WAIT_FOR_ONE.
std::string get_identifier() const
const std::string identifier_
The unique identifier of the SyncPoint.
bool is_watcher(const std::string &component) const
Check if the given component is a watch.
virtual void wait_for_all(const std::string &component)
Wait for all registered emitters.
WakeupType
Type to define when a thread wakes up after waiting for a SyncPoint.
WaitCondition * cond_wait_for_all_
WaitCondition which is used for wait_for_all()
bool operator==(const SyncPoint &other) const
EqualOperator.
Mutex * mutex_
Mutex used to protect all member variables.
A class for handling time.
Wait until a given condition holds.
Fawkes library namespace.