timer.h
Go to the documentation of this file.
1 
26 #ifndef TESSERACT_COMMON_TIMER_H
27 #define TESSERACT_COMMON_TIMER_H
28 
31 #include <functional>
32 #include <chrono>
33 #include <thread>
34 #include <atomic>
36 
37 namespace tesseract_common
38 {
40 class Timer
41 {
42 public:
43  Timer() = default;
44  ~Timer();
45  Timer(const Timer&) = delete;
46  Timer& operator=(const Timer&) = delete;
47  Timer(Timer&&) = delete;
48  Timer& operator=(Timer&&) = delete;
49 
55  void start(const std::function<void()>& callback, std::chrono::steady_clock::duration interval);
56 
58  void stop();
59 
60 private:
61  std::atomic<bool> running_{ false };
62  std::thread timer_thread_;
63 };
64 
65 } // namespace tesseract_common
66 #endif // TESSERACT_COMMON_TIMER_H
tesseract_common::Timer::start
void start(const std::function< void()> &callback, std::chrono::steady_clock::duration interval)
Start the timer with a callback function and a std::chrono::duration interval.
Definition: timer.cpp:33
tesseract_common::Timer
A timer which calls a callback every interval on a separate thread.
Definition: timer.h:40
tesseract_common
Definition: allowed_collision_matrix.h:19
tesseract_common::Timer::timer_thread_
std::thread timer_thread_
Definition: timer.h:62
macros.h
Common Tesseract Macros.
tesseract_common::Timer::~Timer
~Timer()
Definition: timer.cpp:31
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
tesseract_common::Timer::Timer
Timer()=default
tesseract_common::Timer::running_
std::atomic< bool > running_
Definition: timer.h:61
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
Definition: macros.h:72
tesseract_common::Timer::operator=
Timer & operator=(const Timer &)=delete
tesseract_common::Timer::stop
void stop()
Stop the timer.
Definition: timer.cpp:46


tesseract_common
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:40