spdlog
Loading...
Searching...
No Matches
include
spdlog
details
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
20
class
SPDLOG_API
periodic_worker
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
chrono
spdlog::details::periodic_worker
Definition
periodic_worker.h:21
spdlog::details::periodic_worker::worker_thread_
std::thread worker_thread_
Definition
periodic_worker.h:31
spdlog::details::periodic_worker::mutex_
std::mutex mutex_
Definition
periodic_worker.h:32
spdlog::details::periodic_worker::periodic_worker
periodic_worker(const periodic_worker &)=delete
spdlog::details::periodic_worker::active_
bool active_
Definition
periodic_worker.h:30
spdlog::details::periodic_worker::operator=
periodic_worker & operator=(const periodic_worker &)=delete
spdlog::details::periodic_worker::cv_
std::condition_variable cv_
Definition
periodic_worker.h:33
SPDLOG_API
#define SPDLOG_API
Definition
common.h:31
condition_variable
std::chrono::seconds
std::function
functional
mutex
spdlog
Definition
async.h:25
periodic_worker-inl.h
thread
Generated by
1.9.8