20 # if __cplusplus >= 201103L
21 # include <type_traits>
44 virtual
string str()
const
91 return timeout() < rhs.timeout();
94 virtual string str()
const override
98 "Waitable with %s timeout for %s",
103 "Waitable with %s timeout",
117 template <
typename F>
160 template <
typename C>
178 template <
typename C>
201 virtual ~
Waiter()
override;
213 bool polling()
const;
222 virtual void entry()
override;
241 # if __cplusplus >= 201103L
244 typename std::enable_if<!std::is_base_of<TimedWaitable, F>::value,
int>
::type = 0>
251 ZTH_EXPORT
inline void waitUntil(
bool (*f)(), TimeInterval
const& pollInterval = TimeInterval())
262 template <
typename C>
297 ZTH_EXPORT
inline void mnap(
long sleepFor_ms)
299 nap(
TimeInterval((time_t)(sleepFor_ms / 1000L), sleepFor_ms % 1000L * 1000000L));
306 ZTH_EXPORT
inline void unap(
long sleepFor_us)
308 nap(
TimeInterval((time_t)(sleepFor_us / 1000000L), sleepFor_us % 1000000L * 1000L));
446 ZTH_EXPORT
void zth_nap(
struct timespec
const* ts);
447 ZTH_EXPORT
void zth_mnap(
long sleepFor_ms);
448 ZTH_EXPORT
void zth_unap(
long sleepFor_us);
Periodic wakeup after fixed interval.
PeriodicWakeUp(TimeInterval const &interval)
TimeInterval const & interval() const noexcept
PeriodicWakeUp & operator=(TimeInterval const &interval) noexcept
Timestamp const & t() const noexcept
void setInterval(TimeInterval const &interval) noexcept
PolledWaiting< PolledMemberWaitingHelper< C > > base
virtual ~PolledMemberWaiting() override=default
constexpr PolledMemberWaiting(C &that, bool(C::*f)(), TimeInterval const &interval=TimeInterval()) noexcept
virtual bool poll(Timestamp const &now=Timestamp::now()) noexcept override
void setInterval(TimeInterval const &interval, Timestamp const &now=Timestamp::now()) noexcept
TimeInterval const & interval() const noexcept
PolledWaiting(F const &f, TimeInterval const &interval=TimeInterval())
virtual ~PolledWaiting() override=default
Abstract base class of a Poller server.
An abstract class, that can be started as a fiber.
virtual int fiberHook(Fiber &f)
Convenient wrapper around struct timespec that contains a time interval.
constexpr bool hasPassed() const noexcept
virtual bool poll(Timestamp const &now=Timestamp::now()) noexcept override
bool operator<(TimedWaitable const &rhs) const noexcept
void setTimeout(Timestamp const &t) noexcept
Timestamp const & timeout() const noexcept
TimedWaitable(Timestamp const &timeout=Timestamp()) noexcept
virtual string str() const override
virtual ~TimedWaitable() override=default
Convenient wrapper around struct timespec that contains an absolute timestamp.
void setName(string const &name)
void setFiber(Fiber &fiber) noexcept
virtual ~Waitable()=default
virtual string str() const
Fiber & fiber() const noexcept
void resetFiber() noexcept
bool hasFiber() const noexcept
virtual bool poll(Timestamp const &now=Timestamp::now()) noexcept=0
A single fiber per Worker that manages sleeping and blocked fibers.
virtual int fiberHook(Fiber &f) override
The class that manages the fibers within this thread.
void zth_mnap(long sleepFor_ms)
Sleep for the given amount of milliseconds.
void zth_unap(long sleepFor_us)
Sleep for the given amount of microseconds.
void zth_nap(struct timespec const *ts)
Sleep for the given time interval.
void nap(Timestamp const &sleepUntil)
Sleep until the given time stamp.
void mnap(long sleepFor_ms)
Sleep for the given amount of milliseconds.
void waitUntil(TimedWaitable &w)
Wait until the given Waitable has passed.
void unap(long sleepFor_us)
Sleep for the given amount of microseconds.
constexpr auto entry
Guard that is only enabled upon entry of a state.
#define ZTH_CLASS_NEW_DELETE(T)
Define new/delete operators for a class, which are allocator-aware.
void unscheduleTask(TimedWaitable &w)
void scheduleTask(TimedWaitable &w)
string format(char const *fmt,...)
Format like sprintf(), but save the result in an zth::string.
void wakeup(TimedWaitable &w)
constexpr PolledMemberWaitingHelper(C &that, bool(C::*f)()) noexcept
#define zth_assert(expr)
assert(), but better integrated in Zth.
#define likely(expr)
Marks the given expression to likely be evaluated to true.
#define unlikely(expr)
Marks the given expression to likely be evaluated to true.