X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FScheduler.hh;h=033c016e6c74196d1621c65300a14c5cb6ccbda6;hb=556aea04a82b3e2e5cdfe28a0abd3b275c7decf9;hp=c6b0db8c30132b096be01a2fea31b5b402047e57;hpb=8bc8b29a3c4c1b32b14e17d17e3f6c3ff565c9e9;p=senf.git diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index c6b0db8..033c016 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -24,10 +24,11 @@ \brief Scheduler public header */ -#ifndef HH_Scheduler_ -#define HH_Scheduler_ 1 +#ifndef HH_SENF_Scheduler_Scheduler_ +#define HH_SENF_Scheduler_Scheduler_ 1 // Custom includes +#include #include "../Utils/Logger/SenfLog.hh" #include "FdEvent.hh" #include "TimerEvent.hh" @@ -229,9 +230,42 @@ namespace scheduler { /** \brief Current task watchdog timeout */ unsigned taskTimeout(); - /** \brief Number of watchdog events */ + /** \brief Number of watchdog events + + calling hangCount() will reset the counter to 0 + */ unsigned hangCount(); + /** \brief Switch to using hi resolution timers + + By default, timers are implemented directly using epoll. This however restricts the timer + resolution to that of the kernel HZ value. + + High resolution timers are implemented either using POSIX timers or, when available, using + the Linux special \c timerfd() syscall. + + POSIX timers are delivered using signals. A high timer load this increases the signal load + considerably. \c timerfd()'s are delivered on a file descriptor and thus don't have such a + scalability issue. + + \warning The timer source must not be switched from a scheduler callback + */ + void hiresTimers(); + + /** \brief Switch back to using epoll for timing + \see hiresTimers() + */ + void loresTimers(); + + /** \brief return \c true, if \c timerfd() timing is available, \c false otherwise + \see hiresTimers() + */ + bool haveScalableHiresTimers(); + + /** \brief Return \c true, if using hires times, \c false otherwise + \see hiresTimers() */ + bool usingHiresTimers(); + /** \brief Restart scheduler This call will restart all scheduler dispatchers (timers, signals, file descriptors). This @@ -240,7 +274,7 @@ namespace scheduler { */ void restart(); - /** \brief Return \c true, if any event is registered, \c false otherwise. */ + /** \brief Return \c true, if no event is registered, \c false otherwise. */ bool empty(); /** \brief %scheduler specific time source for Utils/Logger framework @@ -261,6 +295,44 @@ namespace scheduler { senf::log::time_type operator()() const; }; + /** \brief Temporarily block all signals + + This class is used to temporarily block all signals in a critical section. + + \code + // Begin critical section + { + senf::scheduler::BlockSignals signalBlocker; + + // critical code executed with all signals blocked + } + // End critical section + \endcode + + You need to take care not to block since even the watchdog timer will be disabled while + executing within a critical section. + */ + class BlockSignals + : boost::noncopyable + { + public: + BlockSignals(bool initiallyBlocked=true); + ///< Block signals until end of scope + /**< \param[in] initiallyBlocked set to \c false to not + automatically block signals initially */ + ~BlockSignals(); ///< Release all signal blocks + + void block(); ///< Block signals if not blocked + void unblock(); ///< Unblock signals if blocked + bool blocked() const; ///< \c true, if signals currently blocked, \c false + ///< otherwise + + private: + bool blocked_; + sigset_t allSigs_; + sigset_t savedSigs_; + }; + }} ///////////////////////////////hh.e////////////////////////////////////////