&& detail::EventHookDispatcher::instance().empty();
}
+prefix_ void senf::scheduler::hiresTimers()
+{
+#ifdef HAVE_TIMERFD
+ if (haveScalableHiresTimers())
+ detail::TimerDispatcher::instance().timerSource(
+ std::auto_ptr<detail::TimerSource>(new detail::TimerFDTimerSource()));
+ else
+#endif
+ detail::TimerDispatcher::instance().timerSource(
+ std::auto_ptr<detail::TimerSource>(new detail::POSIXTimerSource()));
+}
+
///////////////////////////////////////////////////////////////////////////
// senf::schedulerLogTimeSource
return scheduler::detail::FIFORunner::instance().hangCount();
}
-prefix_ void senf::scheduler::hiresTimers()
-{
-#ifdef HAVE_TIMERFD
- if (haveScalableHiresTimers())
- detail::TimerDispatcher::instance().timerSource(
- std::auto_ptr<detail::TimerSource>(new detail::TimerFDTimerSource()));
- else
-#endif
- detail::TimerDispatcher::instance().timerSource(
- std::auto_ptr<detail::TimerSource>(new detail::POSIXTimerSource()));
-}
-
prefix_ void senf::scheduler::loresTimers()
{
detail::TimerDispatcher::instance().timerSource(
#ifndef HAVE_TIMERFD
return false;
#else
- return true;
+ return detail::TimerFDTimerSource::haveTimerFD();
#endif
}
BOOST_MESSAGE( "Using timerfd() hires timers" );
else
BOOST_MESSAGE( "Using POSIX hires timers");
- senf::scheduler::hiresTimers();
+ SENF_CHECK_NO_THROW( senf::scheduler::hiresTimers() );
BOOST_CHECK( senf::scheduler::usingHiresTimers() );
schedulerTest();
- senf::scheduler::loresTimers();
+ SENF_CHECK_NO_THROW( senf::scheduler::loresTimers() );
BOOST_CHECK( ! senf::scheduler::usingHiresTimers() );
}
BOOST_AUTO_UNIT_TEST(testSchedulerPOSIXTimers)
{
if (senf::scheduler::haveScalableHiresTimers()) {
- senf::scheduler::detail::TimerDispatcher::instance().timerSource(
- std::auto_ptr<senf::scheduler::detail::TimerSource>(
- new senf::scheduler::detail::POSIXTimerSource()));
+ SENF_CHECK_NO_THROW( senf::scheduler::detail::TimerDispatcher::instance().timerSource(
+ std::auto_ptr<senf::scheduler::detail::TimerSource>(
+ new senf::scheduler::detail::POSIXTimerSource())) );
schedulerTest();
senf::scheduler::loresTimers();
}
prefix_ void senf::scheduler::detail::TimerFDTimerSource::disable()
{}
+namespace {
+
+ struct TimerFdCheck
+ {
+ TimerFdCheck();
+ bool timerFdOk;
+ };
+
+ TimerFdCheck::TimerFdCheck()
+ : timerFdOk (false)
+ {
+ int fd (timerfd_create(CLOCK_MONOTONIC, 0));
+ if (fd == -1) {
+ if (errno != EINVAL)
+ SENF_THROW_SYSTEM_EXCEPTION("timerfd_create()");
+ }
+ else {
+ timerFdOk = true;
+ close(fd);
+ }
+ }
+
+}
+prefix_ bool senf::scheduler::detail::TimerFDTimerSource::haveTimerFD()
+{
+ static TimerFdCheck check;
+ return check.timerFdOk;
+}
+
prefix_ void senf::scheduler::detail::TimerFDTimerSource::signal(int events)
{
uint64_t expirations (0);
virtual void enable();
virtual void disable();
+ static bool haveTimerFD();
+
private:
virtual void signal(int events);
void reschedule();