periodic_timer.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2020 Intel Corporation. All Rights Reserved.
3 
4 // Helper classes to keep track of time
5 #pragma once
6 
7 #include "timer.h"
8 
9 namespace utilities
10 {
11  namespace time
12  {
13  // A timer class that wakes up every <delta> seconds/minutes/etc. on its bool operator:
14  // Usage example:
15  // periodic_timer timer( chrono::seconds( 5 ));
16  // while(1) {
17  // if( timer ) { /* do something every 5 seconds */ }
18  // }
20  {
21  public:
22 
23  periodic_timer(clock::duration delta)
24  : _delta(delta)
25  {
26  }
27 
28  // Allow use of bool operator for checking time expiration and re trigger when time expired
29  operator bool() const
30  {
31  if (_delta.has_expired())
32  {
33  _delta.start();
34  return true;
35  }
36  return false;
37  }
38 
39  // Force time expiration
40  void set_expired()
41  {
43  }
44  protected:
46  };
47  }
48 }
void start() const
Definition: timer.h:24
void set_expired()
Definition: timer.h:36
periodic_timer(clock::duration delta)
bool has_expired() const
Definition: timer.h:30


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:39