Scheduler.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
18 #ifndef HH_SENF_Scheduler_Scheduler_
19 #define HH_SENF_Scheduler_Scheduler_ 1
20 
21 // Custom includes
22 #include <boost/noncopyable.hpp>
24 #include "FdEvent.hh"
25 #include "TimerEvent.hh"
26 #include "SignalEvent.hh"
27 #include "IdleEvent.hh"
28 #include "EventHook.hh"
29 
30 //#include "scheduler.mpp"
31 //-/////////////////////////////////////////////////////////////////////////////////////////////////
32 
33 namespace senf {
34 
219 namespace scheduler {
220 
228  void process();
229 
231  bool running();
232 
238  void terminate();
239 
245  void yield();
246 
253 
259  ClockService::clock_type const & now();
260 
266 
272  CyclicTimestamp const & eventTimestamp();
273 
279 
284  void watchdogTimeout(unsigned ms);
285 
287  unsigned watchdogTimeout();
288 
293  unsigned watchdogEvents();
294 
300  void watchdogAbort(bool flag);
301 
303  bool watchdogAbort();
304 
319  void hiresTimers();
320 
324  void loresTimers();
325 
330 
333  bool usingHiresTimers();
334 
341  void restart();
342 
344  bool empty();
345 
360  {
361  senf::log::time_type operator()() const;
362  };
363 
382  : boost::noncopyable
383  {
384  public:
385  BlockSignals(bool initiallyBlocked=true);
387 
389  ~BlockSignals();
390 
391  void block();
392  void unblock();
393  bool blocked() const;
394 
396  private:
397  bool blocked_;
398  sigset_t allSigs_;
399  sigset_t savedSigs_;
400  };
401 
402 }}
403 
404 #define SENF_SCHEDULER_WATCHDOG_CHECKPOINT_SET() \
405  senf::scheduler::detail::FIFORunner::instance().watchdogCheckpoint( \
406  __FILE__ ":" BOOST_PP_STRINGIZE(__LINE__));
407 
408 #define SENF_SCHEDULER_WATCHDOG_CHECKPOINT_CLEAR() \
409  senf::scheduler::detail::FIFORunner::instance().watchdogCheckpoint(nullptr);
410 
411 //-/////////////////////////////////////////////////////////////////////////////////////////////////
412 #include "Scheduler.cci"
413 //#include "Scheduler.ct"
414 //#include "Scheduler.cti"
415 #endif
416 
417 
418 // Local Variables:
419 // mode: c++
420 // fill-column: 100
421 // c-file-style: "senf"
422 // indent-tabs-mode: nil
423 // ispell-local-dictionary: "american"
424 // compile-command: "scons -u test"
425 // comment-column: 40
426 // End:
config::time_type clock_type
ClockService timer data type.
Definition: ClockService.hh:78
void watchdogAbort(bool flag)
Enable/disable abort on watchdog event.
bool empty()
Return true, if no event is registered, false otherwise.
Definition: Scheduler.cc:126
void loresTimers()
Switch back to using epoll for timing.
boost::function< void(std::string const &, std::string const &, std::string const &, unsigned, unsigned)> WatchdogCallback
Definition: FIFORunner.hh:42
void hiresTimers()
Switch to using hi resolution timers.
Definition: Scheduler.cc:136
CyclicTimestamp const & eventTimestamp()
Returns the FIFOrunners current event timestamp (1ms precision)
TimerDispatcher public header.
ClockService::clock_type const & now()
Return (approximate) current time.
scheduler specific time source for Utils/Logger framework
Definition: Scheduler.hh:359
void process()
Event handler main loop.
Definition: Scheduler.cc:77
void terminate()
Called by callbacks to terminate the main loop.
Definition: Scheduler.cc:38
SignalDispatcher public header.
EventHook public header.
bool usingHiresTimers()
Return true, if using hires times, false otherwise.
bool haveScalableHiresTimers()
return true, if timerfd() timing is available, false otherwise
senf::log::time_type operator()() const
Definition: Scheduler.cc:151
ClockService::clock_type const & eventTime()
Return timestamp of last event.
FdDispatcher public header.
void watchdogTimeout(unsigned ms)
Set watchdog timeout to ms milliseconds.
bool running()
true, if scheduler is running, false otherwise
Definition: Scheduler.cc:43
ClockService::clock_type nowDiff(ClockService::clock_type const &older)
Returns (approximate) time difference between &#39;older&#39; and now()
IdleEvent public header.
void restart()
Restart scheduler.
Definition: Scheduler.cc:96
Temporarily block all signals.
Definition: Scheduler.hh:381
void yield()
Immediately rescheduler.
Definition: Scheduler.cc:48
void watchdogCallback(detail::FIFORunner::WatchdogCallback const &cb)
Set watchdog hanging callback.
unsigned watchdogEvents()
Number of watchdog events.