spdlog
Loading...
Searching...
No Matches
include
spdlog
details
backtracer-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
7
# include <
spdlog/details/backtracer.h
>
8
#endif
9
namespace
spdlog
{
10
namespace
details {
11
SPDLOG_INLINE
backtracer::backtracer
(
const
backtracer
&other)
12
{
13
std::lock_guard<std::mutex>
lock(other.
mutex_
);
14
enabled_
= other.
enabled
();
15
messages_
= other.
messages_
;
16
}
17
18
SPDLOG_INLINE
backtracer::backtracer
(
backtracer
&&other)
SPDLOG_NOEXCEPT
19
{
20
std::lock_guard<std::mutex>
lock(other.mutex_);
21
enabled_ = other.enabled();
22
messages_ = std::move(other.messages_);
23
}
24
25
SPDLOG_INLINE
backtracer
&
backtracer::operator=
(
backtracer
other)
26
{
27
std::lock_guard<std::mutex>
lock(
mutex_
);
28
enabled_
= other.
enabled
();
29
messages_
= std::move(other.
messages_
);
30
return
*
this
;
31
}
32
33
SPDLOG_INLINE
void
backtracer::enable
(
size_t
size)
34
{
35
std::lock_guard<std::mutex>
lock{
mutex_
};
36
enabled_
.
store
(
true
,
std::memory_order_relaxed
);
37
messages_
=
circular_q<log_msg_buffer>
{size};
38
}
39
40
SPDLOG_INLINE
void
backtracer::disable
()
41
{
42
std::lock_guard<std::mutex>
lock{
mutex_
};
43
enabled_
.
store
(
false
,
std::memory_order_relaxed
);
44
}
45
46
SPDLOG_INLINE
bool
backtracer::enabled
()
const
47
{
48
return
enabled_
.
load
(
std::memory_order_relaxed
);
49
}
50
51
SPDLOG_INLINE
void
backtracer::push_back
(
const
log_msg
&msg)
52
{
53
std::lock_guard<std::mutex>
lock{
mutex_
};
54
messages_
.push_back(
log_msg_buffer
{msg});
55
}
56
57
// pop all items in the q and apply the given fun on each of them.
58
SPDLOG_INLINE
void
backtracer::foreach_pop
(
std::function
<
void
(
const
details::log_msg
&)> fun)
59
{
60
std::lock_guard<std::mutex>
lock{
mutex_
};
61
while
(!
messages_
.empty())
62
{
63
auto
&front_msg =
messages_
.front();
64
fun(front_msg);
65
messages_
.pop_front();
66
}
67
}
68
}
// namespace details
69
}
// namespace spdlog
backtracer.h
spdlog::details::backtracer
Definition
backtracer.h:19
spdlog::details::backtracer::disable
void disable()
Definition
backtracer-inl.h:40
spdlog::details::backtracer::push_back
void push_back(const log_msg &msg)
Definition
backtracer-inl.h:51
spdlog::details::backtracer::operator=
backtracer & operator=(backtracer other)
Definition
backtracer-inl.h:25
spdlog::details::backtracer::enabled_
std::atomic< bool > enabled_
Definition
backtracer.h:21
spdlog::details::backtracer::mutex_
std::mutex mutex_
Definition
backtracer.h:20
spdlog::details::backtracer::backtracer
backtracer()=default
spdlog::details::backtracer::enabled
bool enabled() const
Definition
backtracer-inl.h:46
spdlog::details::backtracer::enable
void enable(size_t size)
Definition
backtracer-inl.h:33
spdlog::details::backtracer::foreach_pop
void foreach_pop(std::function< void(const details::log_msg &)> fun)
Definition
backtracer-inl.h:58
spdlog::details::backtracer::messages_
circular_q< log_msg_buffer > messages_
Definition
backtracer.h:22
spdlog::details::circular_q
Definition
circular_q.h:14
spdlog::details::log_msg_buffer
Definition
log_msg_buffer.h:15
SPDLOG_NOEXCEPT
#define SPDLOG_NOEXCEPT
Definition
common.h:53
SPDLOG_INLINE
#define SPDLOG_INLINE
Definition
common.h:33
std::function
std::atomic::load
T load(T... args)
std::lock_guard
std::make_shared
T make_shared(T... args)
spdlog
Definition
async.h:25
std::atomic::store
T store(T... args)
spdlog::details::log_msg
Definition
log_msg.h:12
Generated by
1.9.8