25 delete m_defaultPoller;
42 yield(NULL,
false, now);
76 if(m_waiting.contains(w))
87 if(m_waiting.contains(w)) {
103 return *m_defaultPoller;
106 return *m_defaultPoller;
139 if(!m_defaultPoller && !m_poller->
empty()) {
147 m_poller = m_defaultPoller;
160 while(!m_waiting.empty() && m_waiting.front().timeout() < now) {
181 bool doRealSleep =
false;
185 if(m_waiting.empty() && !
polling()) {
187 zth_dbg(waiter,
"[%s] No sleeping fibers anymore; suspend",
id_str());
198 if(!m_waiting.empty())
199 end = &m_waiting.front().timeout();
209 zth_dbg(waiter,
"[%s] Out of other work than doing poll()",
214 "[%s] Out of other work than doing poll(); timeout "
218 std::max<int>(0, (
int)(dt.
s<
float>() * 1000.0f));
232 if(res && res != EAGAIN)
235 }
else if(doRealSleep) {
236 zth_dbg(waiter,
"[%s] Out of work; suspend thread, while waiting for %s",
237 id_str(), m_waiting.front().str().c_str());
240 clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &
end->ts(), NULL);
State state() const noexcept
void nap(Timestamp const &sleepUntil=Timestamp::null()) noexcept
void stop(Timestamp const &now=Timestamp::now()) noexcept
void start(Timestamp const &now=Timestamp::now()) noexcept
TimeInterval const & interval() const noexcept
virtual bool empty() const noexcept=0
Checks if there is any pollable registered.
Abstract base class of a Poller server.
virtual int poll(int timeout_ms) noexcept=0
Poll.
virtual int migrateTo(PollerServerBase &p) noexcept=0
Move all registered Pollables to another server.
char const * id_str() const
Fiber * fiber() const noexcept
Convenient wrapper around struct timespec that contains a time interval.
constexpr double s() const noexcept
virtual bool poll(Timestamp const &now=Timestamp::now()) noexcept override
Timestamp const & timeout() const noexcept
Convenient wrapper around struct timespec that contains an absolute timestamp.
constexpr bool isNull() const noexcept
virtual char const * id_str() const override
void setName(string const &name)
void setFiber(Fiber &fiber) noexcept
Fiber & fiber() const noexcept
void resetFiber() noexcept
bool hasFiber() const noexcept
virtual ~Waiter() override
void wakeup(TimedWaitable &w)
void scheduleTask(TimedWaitable &w)
void wait(TimedWaitable &w)
virtual void entry() override
void unscheduleTask(TimedWaitable &w)
PollerServerBase & poller()
void setPoller(PollerServerBase *p=nullptr)
The class that manages the fibers within this thread.
Load_type & load() noexcept
void release(Fiber &fiber) noexcept
Waiter & waiter() noexcept
bool schedule(Fiber *preferFiber=nullptr, Timestamp const &now=Timestamp::now())
void suspend(Fiber &fiber)
void resume(Fiber &fiber) noexcept
Fiber * currentFiber() const noexcept
void add(Fiber *fiber) noexcept
Timestamp const & runEnd() const noexcept
void nap(Timestamp const &sleepUntil)
Sleep until the given time stamp.
Worker & currentWorker() noexcept
Return the (thread-local) singleton Worker instance.
void yield(Fiber *preferFiber=nullptr, bool alwaysYield=false, Timestamp const &now=Timestamp::now())
Allow a context switch.
void waitUntil(TimedWaitable &w)
Wait until the given Waitable has passed.
constexpr auto timeout_ms
A guard that is enabled after a ms milliseconds after entering the current state.
@ end
End-of-guard-list marker.
void perf_mark(char const *marker)
Put a string marker into the perf output.
#define zth_perf_event(...)
Construct a zth::PerfEvent with provided parameters, and forward it to the perf buffer for later proc...
ZmqPoller DefaultPollerServer
The poller server, by default instantiated by the zth::Waiter.
#define zth_dbg(group, fmt, a...)
Debug printf()-like function.
void unscheduleTask(TimedWaitable &w)
void scheduleTask(TimedWaitable &w)
string err(int e)
Return a string like strerror() does, but as a zth::string.
string format(char const *fmt,...)
Format like sprintf(), but save the result in an zth::string.
void perf_syscall(char const *syscall, Timestamp const &t=Timestamp())
Put a syscall into the perf output.
void wakeup(TimedWaitable &w)
static bool const Debug
This is a debug build when set to true.
#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.