34 bool terminate_ (
false);
35 bool running_ (
false);
50 detail::FIFORunner::instance().yield();
57 struct SchedulerScopedInit
62 senf::scheduler::detail::SignalDispatcher::instance().unblockSignals();
63 senf::scheduler::detail::TimerDispatcher::instance().enable();
67 ~SchedulerScopedInit()
69 senf::scheduler::detail::TimerDispatcher::instance().disable();
70 senf::scheduler::detail::SignalDispatcher::instance().blockSignals();
79 SchedulerScopedInit initScheduler;
81 detail::TimerDispatcher::instance().reschedule();
82 while(! terminate_ && ! (detail::FdDispatcher::instance().
empty() &&
83 detail::TimerDispatcher::instance().
empty() &&
84 detail::FileDispatcher::instance().
empty() &&
85 detail::IdleEventDispatcher::instance().
empty()) ) {
86 detail::FdManager::instance().processOnce();
87 detail::FileDispatcher::instance().prepareRun();
88 detail::EventHookDispatcher::instance().prepareRun();
89 detail::TimerDispatcher::instance().prepareRun();
90 detail::IdleEventDispatcher::instance().prepareRun();
91 detail::FIFORunner::instance().run();
92 detail::TimerDispatcher::instance().reschedule();
100 detail::FdDispatcher* fdd (&detail::FdDispatcher::instance());
101 detail::TimerDispatcher* tdd (&detail::TimerDispatcher::instance());
102 detail::SignalDispatcher* sdd (&detail::SignalDispatcher::instance());
103 detail::FileDispatcher* fld (&detail::FileDispatcher::instance());
104 detail::IdleEventDispatcher* ied (&detail::IdleEventDispatcher::instance());
105 detail::EventHookDispatcher* eed (&detail::EventHookDispatcher::instance());
107 eed->~EventHookDispatcher();
108 ied->~IdleEventDispatcher();
109 fld->~FileDispatcher();
110 sdd->~SignalDispatcher();
111 tdd->~TimerDispatcher();
112 fdd->~FdDispatcher();
118 new (fdd) detail::FdDispatcher();
119 new (tdd) detail::TimerDispatcher();
120 new (sdd) detail::SignalDispatcher();
121 new (fld) detail::FileDispatcher();
122 new (ied) detail::IdleEventDispatcher();
123 new (eed) detail::EventHookDispatcher();
128 return detail::FdDispatcher::instance().empty()
129 && detail::TimerDispatcher::instance().empty()
130 && detail::FileDispatcher::instance().empty()
131 && detail::SignalDispatcher::instance().empty()
132 && detail::IdleEventDispatcher::instance().empty()
133 && detail::EventHookDispatcher::instance().empty();
138 #ifdef HAVE_TIMERFD_CREATE 140 detail::TimerDispatcher::instance().timerSource(
141 std::unique_ptr<detail::TimerSource>(
new detail::TimerFDTimerSource()));
144 detail::TimerDispatcher::instance().timerSource(
163 ::sigfillset(&allSigs_);
164 if (initiallyBlocked)
172 ::sigprocmask(SIG_BLOCK, &allSigs_, &savedSigs_);
180 ::sigprocmask(SIG_SETMASK, &savedSigs_, 0);
bool empty()
Return true, if no event is registered, false otherwise.
void hiresTimers()
Switch to using hi resolution timers.
ClockService::clock_type const & now()
Return (approximate) current time.
void process()
Event handler main loop.
void terminate()
Called by callbacks to terminate the main loop.
BlockSignals(bool initiallyBlocked=true)
Block signals until end of scope.
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_nanoseconds(clock_type const &v)
Convert v to nanoseconds.
bool haveScalableHiresTimers()
return true, if timerfd() timing is available, false otherwise
senf::log::time_type operator()() const
bool running()
true, if scheduler is running, false otherwise
void restart()
Restart scheduler.
void yield()
Immediately rescheduler.
void block()
Block signals if not blocked.
void unblock()
Unblock signals if blocked.