6 #ifndef UTILS_CALLBACK_TIMER_H 7 #define UTILS_CALLBACK_TIMER_H 12 #include <Utils/Threading.h> 36 if (execute_.load(std::memory_order_acquire))
52 template<
typename DurationType>
53 void Start(DurationType interval, std::function<
bool(
void)> callback)
55 if (execute_.load(std::memory_order_acquire))
60 execute_.store(
true, std::memory_order_release);
61 thread_ = std::thread([
this, interval, callback]()
63 utils::SetThisThreadName(
"CallbackTimer_thread");
64 while (execute_.load(std::memory_order_acquire))
66 execute_.store(callback(), std::memory_order_release);
67 std::this_thread::sleep_for(interval);
75 execute_.store(
false, std::memory_order_release);
76 if (thread_.joinable())
83 bool IsRunning() const noexcept
85 return (execute_.load(std::memory_order_acquire) && thread_.joinable());
90 std::atomic<bool> execute_;
General namespace for utilities.
Definition: BulletConversions.h:9