JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Watchdog.H
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2021 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #pragma once
19 
20 #include <future>
21 
22 namespace jevois
23 {
24  //! Simple watchdog class
25  /*! This class will kill the current process if reset() is not called at least every timeout seconds. If timeout <=
26  0.0 then the watchdog is inactive (will never time out and kill the process). Note that to be as lightweight as
27  possible, this class runs a background thread with a loop that iterates every timeout seconds, so the exact kill
28  time is approximate. \ingroup debugging */
29  class Watchdog
30  {
31  public:
32  //! Constructor
33  Watchdog(double timeout);
34 
35  //! Virtual destructor for safe inheritance
36  ~Watchdog();
37 
38  //! Reset our internal timer. If this does not happen at least every timeout seconds, process is killed
39  void reset();
40 
41  protected:
42  void run(double timeout);
43  std::future<void> itsRunFut;
44  std::atomic<bool> itsReset = true;
45  std::atomic<bool> itsRunning = false;
46  };
47 }
jevois::Watchdog::reset
void reset()
Reset our internal timer. If this does not happen at least every timeout seconds, process is killed.
Definition: Watchdog.C:47
jevois::Watchdog::~Watchdog
~Watchdog()
Virtual destructor for safe inheritance.
Definition: Watchdog.C:37
jevois::Watchdog::itsReset
std::atomic< bool > itsReset
Definition: Watchdog.H:44
jevois::Watchdog
Simple watchdog class.
Definition: Watchdog.H:29
jevois
Definition: Concepts.dox:1
jevois::Watchdog::itsRunFut
std::future< void > itsRunFut
Definition: Watchdog.H:43
jevois::Watchdog::Watchdog
Watchdog(double timeout)
Constructor.
Definition: Watchdog.C:27
jevois::Watchdog::itsRunning
std::atomic< bool > itsRunning
Definition: Watchdog.H:45
jevois::Watchdog::run
void run(double timeout)
Definition: Watchdog.C:51