spdlog
Loading...
Searching...
No Matches
periodic_worker.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// periodic worker thread - periodically executes the given callback function.
7//
8// RAII over the owned thread:
9// creates the thread on construction.
10// stops and joins the thread on destruction (if the thread is executing a callback, wait for it to finish first).
11
12#include <chrono>
13#include <condition_variable>
14#include <functional>
15#include <mutex>
16#include <thread>
17namespace spdlog {
18namespace details {
19
21{
22public:
23 periodic_worker(const std::function<void()> &callback_fun, std::chrono::seconds interval);
26 // stop the worker thread and join it
28
29private:
30 bool active_;
34};
35} // namespace details
36} // namespace spdlog
37
38#ifdef SPDLOG_HEADER_ONLY
39# include "periodic_worker-inl.h"
40#endif
periodic_worker(const periodic_worker &)=delete
periodic_worker & operator=(const periodic_worker &)=delete
std::condition_variable cv_
#define SPDLOG_API
Definition common.h:31
Definition async.h:25