6 const double period_seconds) :
9 std::chrono::duration<size_t, std::micro>(size_t(period_seconds * 1e6));
14 if(!(
period_us.count() > 0))
return false;
16 if(
running_.test_and_set())
return false;
21 thread_ptr = std::shared_ptr<std::thread>(
new std::thread([
this] {
23 tstart = std::chrono::steady_clock::now();
58 std::chrono::duration<size_t, std::micro>(size_t(period_seconds * 1e6));
bool start()
start define and start background thread
std::atomic_flag running_
bool stop()
stop tell thread to stop and wait for end
std::function< void()> funct
void setPeriod(const double &period_seconds)
setPeriod change the update period of timer thread This will stop and restart the thread...
std::shared_ptr< std::thread > thread_ptr
std::chrono::duration< size_t, std::micro > period_us
std::timed_mutex mutex_timer
std::chrono::steady_clock::time_point tstart
PeriodicTimer(const std::function< void()> funct, const double period_seconds)
PeriodicTimer define a periodic timer.