spdlog
Loading...
Searching...
No Matches
periodic_worker-inl.h
Go to the documentation of this file.
1// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
2// Distributed under the MIT License (http://opensource.org/licenses/MIT)
3
4#pragma once
5
6#ifndef SPDLOG_HEADER_ONLY
8#endif
9
10namespace spdlog {
11namespace details {
12
14{
15 active_ = (interval > std::chrono::seconds::zero());
16 if (!active_)
17 {
18 return;
19 }
20
21 worker_thread_ = std::thread([this, callback_fun, interval]() {
22 for (;;)
23 {
25 if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; }))
26 {
27 return; // active_ == false, so exit this thread
28 }
29 callback_fun();
30 }
31 });
32}
33
34// stop the worker thread and join it
47
48} // namespace details
49} // namespace spdlog
periodic_worker(const std::function< void()> &callback_fun, std::chrono::seconds interval)
std::condition_variable cv_
#define SPDLOG_INLINE
Definition common.h:33
T join(T... args)
T joinable(T... args)
Definition async.h:25