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

Last change on this file since 16 was 15, checked in by Bayard Gildas, 6 years ago

sources reformatted with flair-format-dir script

File size: 1.1 KB
RevLine 
[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
19namespace flair {
20namespace core {
21
[15]22Watchdog::Watchdog(const Object *parent, std::function<void()> _expired,
23 Time _timer)
24 : Thread(parent, "watchdog", 0), expired(_expired), timer(_timer) {}
[2]25
26Watchdog::~Watchdog() {
[15]27 SafeStop();
28 Join();
[2]29}
30
31void Watchdog::Touch() {
[15]32 if (IsSuspended())
33 Resume();
[2]34}
35
36void Watchdog::SetTimer(Time _Timer) {
[15]37 timer = _Timer;
38 Touch();
[2]39}
40
41void Watchdog::Run() {
[15]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
46 // %llu\n",current,date);
47 if (!SuspendUntil(date)) {
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.