Rev | Line | |
---|
[2] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 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 |
|
---|
[15] | 22 | Watchdog::Watchdog(const Object *parent, std::function<void()> _expired,
|
---|
| 23 | Time _timer)
|
---|
[213] | 24 | : Thread(parent, "watchdog", 0,16384*2), expired(_expired), timer(_timer) {}
|
---|
[2] | 25 |
|
---|
| 26 | Watchdog::~Watchdog() {
|
---|
[15] | 27 | SafeStop();
|
---|
| 28 | Join();
|
---|
[2] | 29 | }
|
---|
| 30 |
|
---|
| 31 | void Watchdog::Touch() {
|
---|
[15] | 32 | if (IsSuspended())
|
---|
| 33 | Resume();
|
---|
[2] | 34 | }
|
---|
| 35 |
|
---|
| 36 | void Watchdog::SetTimer(Time _Timer) {
|
---|
[15] | 37 | timer = _Timer;
|
---|
| 38 | Touch();
|
---|
[2] | 39 | }
|
---|
| 40 |
|
---|
| 41 | void Watchdog::Run() {
|
---|
[15] | 42 | while (!ToBeStopped()) {
|
---|
| 43 | Time current = GetTime();
|
---|
| 44 | Time date = current + timer;
|
---|
[252] | 45 | //Printf("watchdog goes to sleep at %llu, scheduled to wake up at %llu\n",current,date);
|
---|
[15] | 46 | if (!SuspendUntil(date)) {
|
---|
[252] | 47 | //Printf("watchdog expired at %llu!!!!!!!!!!!!!!!!\n",GetTime());
|
---|
[15] | 48 | expired();
|
---|
[2] | 49 | }
|
---|
[15] | 50 | }
|
---|
[2] | 51 | };
|
---|
| 52 |
|
---|
| 53 | } // end namespace core
|
---|
| 54 | } // end namespace flair
|
---|
Note:
See
TracBrowser
for help on using the repository browser.