Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
6255180e
Commit
6255180e
authored
Dec 05, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small fixes in async_helper
parent
52d02af9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
41 deletions
+20
-41
include/spdlog/details/async_log_helper.h
include/spdlog/details/async_log_helper.h
+18
-36
include/spdlog/details/async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+2
-5
No files found.
include/spdlog/details/async_log_helper.h
View file @
6255180e
...
...
@@ -37,6 +37,7 @@
#include <thread>
#include <atomic>
#include "../common.h"
#include "../sinks/sink.h"
#include "./mpmc_bounded_q.h"
#include "./log_msg.h"
...
...
@@ -108,38 +109,35 @@ public:
using
clock
=
std
::
chrono
::
steady_clock
;
explicit
async_log_helper
(
size_t
queue_size
);
async_log_helper
(
formatter_ptr
formatter
,
const
std
::
vector
<
sink_ptr
>&
sinks
,
size_t
queue_size
);
void
log
(
const
details
::
log_msg
&
msg
);
//Stop logging and join the back thread
~
async_log_helper
();
void
add_sink
(
sink_ptr
sink
);
void
remove_sink
(
sink_ptr
sink_ptr
);
~
async_log_helper
();
void
set_formatter
(
formatter_ptr
);
//Wait to remaining items (if any) in the queue to be written and shutdown
void
shutdown
(
const
log_clock
::
duration
&
timeout
);
private:
std
::
vector
<
std
::
shared_ptr
<
sinks
::
sink
>>
_sinks
;
std
::
atomic
<
bool
>
_active
;
private:
std
::
atomic
<
bool
>
_active
;
formatter_ptr
_formatter
;
std
::
vector
<
std
::
shared_ptr
<
sinks
::
sink
>>
_sinks
;
q_type
_q
;
std
::
thread
_worker_thread
;
std
::
mutex
_mutex
;
std
::
thread
_worker_thread
;
// last exception thrown from the worker thread
std
::
shared_ptr
<
spdlog_ex
>
_last_workerthread_ex
;
// worker thread formatter
formatter_ptr
_formatter
;
// will throw last worker thread exception or if worker thread no active
void
throw_if_bad_worker
();
// worker thread loop
void
thread
_loop
();
void
worker
_loop
();
// guess how much to sleep if queue is empty/full using last succesful op time as hint
static
void
sleep_or_yield
(
const
clock
::
time_point
&
last_op_time
);
...
...
@@ -156,11 +154,12 @@ private:
///////////////////////////////////////////////////////////////////////////////
// async_sink class implementation
///////////////////////////////////////////////////////////////////////////////
inline
spdlog
::
details
::
async_log_helper
::
async_log_helper
(
size_t
queue_size
)
:
_sinks
(),
_active
(
true
),
inline
spdlog
::
details
::
async_log_helper
::
async_log_helper
(
formatter_ptr
formatter
,
const
std
::
vector
<
sink_ptr
>&
sinks
,
size_t
queue_size
)
:
_active
(
false
),
_formatter
(
formatter
),
_sinks
(
sinks
),
_q
(
queue_size
),
_worker_thread
(
&
async_log_helper
::
thread
_loop
,
this
)
_worker_thread
(
&
async_log_helper
::
worker
_loop
,
this
)
{}
inline
spdlog
::
details
::
async_log_helper
::~
async_log_helper
()
...
...
@@ -190,12 +189,11 @@ inline void spdlog::details::async_log_helper::log(const details::log_msg& msg)
}
inline
void
spdlog
::
details
::
async_log_helper
::
thread
_loop
()
inline
void
spdlog
::
details
::
async_log_helper
::
worker
_loop
()
{
log_msg
popped_log_msg
;
clock
::
time_point
last_pop
=
clock
::
now
();
size_t
counter
=
0
;
clock
::
time_point
last_pop
=
clock
::
now
();
_active
=
true
;
while
(
_active
)
{
q_type
::
item_type
popped_msg
;
...
...
@@ -229,27 +227,11 @@ inline void spdlog::details::async_log_helper::thread_loop()
}
inline
void
spdlog
::
details
::
async_log_helper
::
add_sink
(
spdlog
::
sink_ptr
s
)
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
_mutex
);
_sinks
.
push_back
(
s
);
}
inline
void
spdlog
::
details
::
async_log_helper
::
remove_sink
(
spdlog
::
sink_ptr
s
)
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
_mutex
);
_sinks
.
erase
(
std
::
remove
(
_sinks
.
begin
(),
_sinks
.
end
(),
s
),
_sinks
.
end
());
}
inline
void
spdlog
::
details
::
async_log_helper
::
set_formatter
(
formatter_ptr
msg_formatter
)
{
_formatter
=
msg_formatter
;
}
inline
void
spdlog
::
details
::
async_log_helper
::
shutdown
(
const
log_clock
::
duration
&
timeout
)
{
/*
...
...
include/spdlog/details/async_logger_impl.h
View file @
6255180e
...
...
@@ -37,11 +37,8 @@ template<class It>
inline
spdlog
::
async_logger
::
async_logger
(
const
std
::
string
&
logger_name
,
const
It
&
begin
,
const
It
&
end
,
size_t
queue_size
,
const
log_clock
::
duration
&
shutdown_duration
)
:
logger
(
logger_name
,
begin
,
end
),
_shutdown_duration
(
shutdown_duration
),
_async_log_helper
(
new
details
::
async_log_helper
(
queue_size
))
{
_async_log_helper
->
set_formatter
(
_formatter
);
for
(
auto
&
s
:
_sinks
)
_async_log_helper
->
add_sink
(
s
);
_async_log_helper
(
new
details
::
async_log_helper
(
_formatter
,
_sinks
,
queue_size
))
{
}
inline
spdlog
::
async_logger
::
async_logger
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
,
size_t
queue_size
,
const
log_clock
::
duration
&
shutdown_duration
)
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment