Agora  1.2.0
Agora project
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>
17 namespace spdlog {
18 namespace details {
19 
21 {
22 public:
23  periodic_worker(const std::function<void()> &callback_fun, std::chrono::seconds interval);
24  periodic_worker(const periodic_worker &) = delete;
25  periodic_worker &operator=(const periodic_worker &) = delete;
26  // stop the worker thread and join it
27  ~periodic_worker();
28 
29 private:
30  bool active_;
31  std::thread worker_thread_;
32  std::mutex mutex_;
33  std::condition_variable cv_;
34 };
35 } // namespace details
36 } // namespace spdlog
37 
38 #ifdef SPDLOG_HEADER_ONLY
39 # include "periodic_worker-inl.h"
40 #endif
spdlog::details::periodic_worker::mutex_
std::mutex mutex_
Definition: periodic_worker.h:32
periodic_worker-inl.h
spdlog::details::periodic_worker::cv_
std::condition_variable cv_
Definition: periodic_worker.h:33
spdlog::details::periodic_worker
Definition: periodic_worker.h:20
spdlog
Definition: async.h:25
spdlog::details::periodic_worker::worker_thread_
std::thread worker_thread_
Definition: periodic_worker.h:31
function
function[avg_proc_duration, std_proc_duration]
Definition: parse_dl_file.m:1
SPDLOG_API
#define SPDLOG_API
Definition: common.h:40
spdlog::details::periodic_worker::active_
bool active_
Definition: periodic_worker.h:30