Rev | Line | |
---|
| 1 | // %flair:license{
|
---|
| 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
| 4 | // %flair:license}
|
---|
| 5 | // created: 2016/02/25
|
---|
| 6 | // filename: Watchdog.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Gildas Bayard
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Watchdog class
|
---|
| 14 | //
|
---|
| 15 | /*********************************************************************/
|
---|
| 16 |
|
---|
| 17 | #include "Watchdog.h"
|
---|
| 18 |
|
---|
| 19 | namespace flair {
|
---|
| 20 | namespace core {
|
---|
| 21 |
|
---|
| 22 | Watchdog::Watchdog(const Object* parent,std::function<void()> _expired,Time _timer):Thread(parent,"watchdog",0),expired(_expired),timer(_timer){
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | Watchdog::~Watchdog() {
|
---|
| 26 | SafeStop();
|
---|
| 27 | Join();
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | void Watchdog::Touch() {
|
---|
| 31 | if (IsSuspended()) Resume();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | void Watchdog::SetTimer(Time _Timer) {
|
---|
| 35 | timer=_Timer; Touch();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | void Watchdog::Run() {
|
---|
| 39 | while (!ToBeStopped()) {
|
---|
| 40 | Time current=GetTime();
|
---|
| 41 | Time date=current+timer;
|
---|
| 42 | //Printf("watchdog goes to sleep at %llu, scheduled to wake up at %llu\n",current,date);
|
---|
| 43 | if (!SuspendUntil(date)) {
|
---|
| 44 | expired();
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | } // end namespace core
|
---|
| 50 | } // end namespace flair
|
---|
Note:
See
TracBrowser
for help on using the repository browser.