19# if __cplusplus >= 201103L
20# include <type_traits>
43 virtual
string str()
const
88 return timeout() < rhs.timeout();
91 virtual string str()
const override
95 "Waitable with %s timeout for %s",
100 "Waitable with %s timeout",
198 virtual ~Waiter()
noexcept override;
210 bool polling()
const;
219 virtual void entry()
override;
232ZTH_EXPORT
void waitUntil(TimedWaitable& w);
238# if __cplusplus >= 201103L
241 typename std::enable_if<!std::is_base_of<TimedWaitable, F>::value,
int>::type = 0>
248ZTH_EXPORT
inline void waitUntil(
bool (*f)(), TimeInterval
const& pollInterval = TimeInterval())
250 PolledWaiting<bool (*)()> w(f, pollInterval);
268void wakeup(TimedWaitable& w);
294ZTH_EXPORT
inline void mnap(
long sleepFor_ms)
296 nap(
TimeInterval((time_t)(sleepFor_ms / 1000L), sleepFor_ms % 1000L * 1000000L));
303ZTH_EXPORT
inline void unap(
long sleepFor_us)
305 nap(
TimeInterval((time_t)(sleepFor_us / 1000000L), sleepFor_us % 1000000L * 1000L));
362 : m_interval(interval)
378 m_interval = interval;
383 setInterval(interval);
441ZTH_EXPORT
void zth_nap(
struct timespec
const* ts);
442ZTH_EXPORT
void zth_mnap(
long sleepFor_ms);
443ZTH_EXPORT
void zth_unap(
long sleepFor_us);
void setName(string const &name)
Periodic wakeup after fixed interval.
PeriodicWakeUp(TimeInterval const &interval)
TimeInterval const & interval() const noexcept
Timestamp const & t() const noexcept
void setInterval(TimeInterval const &interval) noexcept
PeriodicWakeUp & operator=(TimeInterval const &interval) noexcept
PolledWaiting< PolledMemberWaitingHelper< C > > base
virtual ~PolledMemberWaiting() noexcept 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
virtual ~PolledWaiting() noexcept override=default
PolledWaiting(F const &f, TimeInterval const &interval=TimeInterval())
TimeInterval const & interval() const noexcept
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() noexcept override=default
Convenient wrapper around struct timespec that contains an absolute timestamp.
void setFiber(Fiber &fiber) noexcept
virtual string str() const
void resetFiber() noexcept
virtual ~Waitable() noexcept=default
bool hasFiber() const noexcept
virtual bool poll(Timestamp const &now=Timestamp::now()) noexcept=0
Fiber & fiber() const noexcept
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.
#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.