source: flair-src/trunk/lib/FlairCore/src/Watchdog.cpp @ 2

Last change on this file since 2 was 2, checked in by Sanahuja Guillaume, 6 years ago

flaircore

File size: 1.1 KB
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
19namespace flair {
20namespace core {
21
22Watchdog::Watchdog(const Object* parent,std::function<void()> _expired,Time _timer):Thread(parent,"watchdog",0),expired(_expired),timer(_timer){
23}
24
25Watchdog::~Watchdog() {
26    SafeStop();
27    Join();
28}
29
30void Watchdog::Touch() {
31    if (IsSuspended()) Resume();
32}
33
34void Watchdog::SetTimer(Time _Timer) {
35    timer=_Timer; Touch();
36}
37
38void 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.