22 #ifdef HAVE_TIMERFD_CREATE 23 #include TIMERFD_H_PATH 41 : timeoutEnabled_ (false), timeout_ (0), signalEnabled_ (false)
43 if (pipe(timerPipe_) < 0)
47 sigemptyset(&sigSet_);
48 sigaddset(&sigSet_, SIGALRM);
49 sigprocmask(SIG_BLOCK, &sigSet_, 0);
52 act.sa_sigaction = &sigHandler;
53 act.sa_mask = sigSet_;
54 act.sa_flags = SA_SIGINFO | SA_RESTART;
55 if (sigaction(SIGALRM, &act, 0) < 0)
59 ::memset(&ev, 0,
sizeof(ev));
60 ev.sigev_notify = SIGEV_SIGNAL;
61 ev.sigev_signo = SIGALRM;
62 ev.sigev_value.sival_ptr =
this;
63 if (timer_create(CLOCK_MONOTONIC, &ev, &timerId_) < 0)
69 timer_delete(timerId_);
70 ::signal(SIGALRM, SIG_IGN);
71 sigprocmask(SIG_UNBLOCK, &sigSet_, 0);
80 if (! timeoutEnabled_ || timeout_ != timeout) {
84 timeoutEnabled_ =
true;
91 if (timeoutEnabled_) {
92 timeoutEnabled_ =
false;
99 if (! signalEnabled_) {
100 signalEnabled_ =
true;
101 sigprocmask(SIG_UNBLOCK, &sigSet_, 0);
107 if (signalEnabled_) {
108 signalEnabled_ =
false;
109 sigprocmask(SIG_BLOCK, &sigSet_, 0);
113 prefix_ void senf::scheduler::detail::POSIXTimerSource::sigHandler(
int,
114 ::siginfo_t * siginfo,
117 if (siginfo->si_value.sival_ptr == 0)
119 static char data =
'\xD0';
121 senf::IGNORE( write(static_cast<POSIXTimerSource*>(siginfo->si_value.sival_ptr)->timerPipe_[1],
122 &data,
sizeof(data)) );
125 prefix_ void senf::scheduler::detail::POSIXTimerSource::signal(
int events)
130 senf::IGNORE( read(timerPipe_[0], &data,
sizeof(data)) );
131 timeoutEnabled_ =
false;
134 prefix_ void senf::scheduler::detail::POSIXTimerSource::reschedule()
136 struct itimerspec timer;
137 memset(&timer.it_interval, 0,
sizeof(timer.it_interval));
138 if (timeoutEnabled_) {
142 if (
SENF_UNLIKELY(timer_settime(timerId_, TIMER_ABSTIME, &timer, 0)<0))
153 IdleEventDispatcher::instance().timeout(delay<0?0:delay);
158 IdleEventDispatcher::instance().timeout(-1);
170 #ifdef HAVE_TIMERFD_CREATE 171 prefix_ senf::scheduler::detail::TimerFDTimerSource::TimerFDTimerSource()
172 : timerfd_ (-1), timeoutEnabled_ (
false), timeout_(0)
174 timerfd_ = timerfd_create(CLOCK_MONOTONIC, 0);
180 prefix_ senf::scheduler::detail::TimerFDTimerSource::~TimerFDTimerSource()
189 if (!timeoutEnabled_ || timeout_ != timeout) {
193 timeoutEnabled_ =
true;
198 prefix_ void senf::scheduler::detail::TimerFDTimerSource::notimeout()
200 if (timeoutEnabled_) {
201 timeoutEnabled_ =
false;
206 prefix_ void senf::scheduler::detail::TimerFDTimerSource::enable()
209 prefix_ void senf::scheduler::detail::TimerFDTimerSource::disable()
220 TimerFdCheck::TimerFdCheck()
223 int fd (timerfd_create(CLOCK_MONOTONIC, 0));
236 prefix_ bool senf::scheduler::detail::TimerFDTimerSource::haveTimerFD()
238 static TimerFdCheck check;
239 return check.timerFdOk;
242 prefix_ void senf::scheduler::detail::TimerFDTimerSource::signal(
int events)
244 uint64_t expirations (0);
246 senf::IGNORE( read(timerfd_, &expirations,
sizeof(expirations)) );
249 prefix_ void senf::scheduler::detail::TimerFDTimerSource::reschedule()
251 struct itimerspec timer;
252 memset(&timer.it_interval, 0,
sizeof(timer.it_interval));
253 if (timeoutEnabled_) {
257 if (
SENF_UNLIKELY(timerfd_settime(timerfd_, TFD_TIMER_ABSTIME, &timer, 0)<0))
config::time_type clock_type
ClockService timer data type.
#define SENF_THROW_SYSTEM_EXCEPTION(desc)
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_milliseconds(clock_type const &v)
Convert v to milliseconds.
TimerSource public header.
u8 data[SPECTRAL_HT20_NUM_BINS]
virtual void timeout(ClockService::clock_type const &timeout)
ClockService::clock_type const & now()
Return (approximate) current time.
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_nanoseconds(clock_type const &v)
Convert v to nanoseconds.
virtual void timeout(ClockService::clock_type const &timeout)
static clock_type now()
Return current clock value.
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_seconds(clock_type const &v)
Convert v to seconds.