23 #ifndef GUL14_TRIGGER_H_
24 #define GUL14_TRIGGER_H_
27 #include <condition_variable>
114 explicit Trigger(
bool triggered =
false) noexcept : triggered_{ triggered }
144 operator
bool() const noexcept;
151 Trigger& operator=(
bool interrupt) noexcept;
155 void reset() noexcept;
188 template <class Rep, class Period>
189 bool wait_for(const std::chrono::duration<Rep, Period>& delta_t)
const
191 std::unique_lock<std::mutex> lock(mutex_);
192 return cv_.wait_for(lock, delta_t, [
this]{
return triggered_; });
211 template <
class Clock,
class Duration>
212 bool wait_until(
const std::chrono::time_point<Clock, Duration>& t)
const
214 std::unique_lock<std::mutex> lock(mutex_);
215 return cv_.wait_until(lock, t, [
this]{
return triggered_; });
219 mutable std::mutex mutex_;
220 mutable std::condition_variable cv_;
221 bool triggered_ =
false;
A class that allows sending triggers and waiting for them across different threads.
Definition: Trigger.h:111
GUL_EXPORT void reset() noexcept
Set the trigger to low (false).
Definition: Trigger.cc:54
Trigger(bool triggered=false) noexcept
Constructor.
Definition: Trigger.h:114
GUL_EXPORT ~Trigger() noexcept
Destructor: Send a final trigger signal so that all threads waiting on this object have a chance to s...
Definition: Trigger.cc:28
bool wait_until(const std::chrono::time_point< Clock, Duration > &t) const
Suspend execution of the current thread until the trigger goes high (true) or the given time point ha...
Definition: Trigger.h:212
GUL_EXPORT void trigger() noexcept
Set the trigger to high (true).
Definition: Trigger.cc:60
bool wait_for(const std::chrono::duration< Rep, Period > &delta_t) const
Suspend execution of the current thread until the trigger goes high (true) or at least the given time...
Definition: Trigger.h:189
GUL_EXPORT void wait() const
Suspend execution of the current thread until the trigger goes high (true).
Definition: Trigger.cc:72
Definition of macros used internally by GUL.
Namespace gul14 contains all functions and classes of the General Utility Library.
Definition: doxygen.h:26