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,
|
---|
23 | Time _timer)
|
---|
24 | : Thread(parent, "watchdog", 0,16384*2), expired(_expired), timer(_timer) {}
|
---|
25 |
|
---|
26 | Watchdog::~Watchdog() {
|
---|
27 | SafeStop();
|
---|
28 | Join();
|
---|
29 | }
|
---|
30 |
|
---|
31 | void Watchdog::Touch() {
|
---|
32 | if (IsSuspended())
|
---|
33 | Resume();
|
---|
34 | }
|
---|
35 |
|
---|
36 | void Watchdog::SetTimer(Time _Timer) {
|
---|
37 | timer = _Timer;
|
---|
38 | Touch();
|
---|
39 | }
|
---|
40 |
|
---|
41 | void Watchdog::Run() {
|
---|
42 | while (!ToBeStopped()) {
|
---|
43 | Time current = GetTime();
|
---|
44 | Time date = current + timer;
|
---|
45 | //Printf("watchdog goes to sleep at %llu, scheduled to wake up at %llu\n",current,date);
|
---|
46 | if (!SuspendUntil(date)) {
|
---|
47 | //Printf("watchdog expired at %llu!!!!!!!!!!!!!!!!\n",GetTime());
|
---|
48 | expired();
|
---|
49 | }
|
---|
50 | }
|
---|
51 | };
|
---|
52 |
|
---|
53 | } // end namespace core
|
---|
54 | } // end namespace flair
|
---|
Note:
See
TracBrowser
for help on using the repository browser.