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
fd7650a8
Commit
fd7650a8
authored
Dec 21, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more graceful shutdown of worker thread in async
parent
b1867cfb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
17 deletions
+18
-17
include/spdlog/details/async_log_helper.h
include/spdlog/details/async_log_helper.h
+18
-17
No files found.
include/spdlog/details/async_log_helper.h
View file @
fd7650a8
...
@@ -141,10 +141,6 @@ private:
...
@@ -141,10 +141,6 @@ private:
// guess how much to sleep if queue is empty/full using last succesful op time as hint
// 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
);
static
void
sleep_or_yield
(
const
clock
::
time_point
&
last_op_time
);
// clear all remaining messages(if any), stop the _worker_thread and join it
void
join_worker
();
};
};
}
}
}
}
...
@@ -160,9 +156,17 @@ inline spdlog::details::async_log_helper::async_log_helper(formatter_ptr formatt
...
@@ -160,9 +156,17 @@ inline spdlog::details::async_log_helper::async_log_helper(formatter_ptr formatt
_worker_thread
(
&
async_log_helper
::
worker_loop
,
this
)
_worker_thread
(
&
async_log_helper
::
worker_loop
,
this
)
{}
{}
// Send to the worker thread termination message(level=off)
// and wait for it to finish gracefully
inline
spdlog
::
details
::
async_log_helper
::~
async_log_helper
()
inline
spdlog
::
details
::
async_log_helper
::~
async_log_helper
()
{
{
join_worker
();
log
(
log_msg
(
level
::
off
));
try
{
_worker_thread
.
join
();
}
catch
(
const
std
::
system_error
&
)
//Dont crash if thread not joinable
{}
}
}
...
@@ -193,7 +197,9 @@ inline void spdlog::details::async_log_helper::worker_loop()
...
@@ -193,7 +197,9 @@ inline void spdlog::details::async_log_helper::worker_loop()
}
}
}
}
//Process next message in the queue
//Return true if message was processed in the queue, or false if queue was empty
//Will set _active to be false upon receiving log_msg with level==off (idicating the worker need to die)
inline
bool
spdlog
::
details
::
async_log_helper
::
process_next_msg
(
clock
::
time_point
&
last_pop
)
inline
bool
spdlog
::
details
::
async_log_helper
::
process_next_msg
(
clock
::
time_point
&
last_pop
)
{
{
...
@@ -206,7 +212,12 @@ inline bool spdlog::details::async_log_helper::process_next_msg(clock::time_poin
...
@@ -206,7 +212,12 @@ inline bool spdlog::details::async_log_helper::process_next_msg(clock::time_poin
try
try
{
{
incoming_async_msg
.
fill_log_msg
(
incoming_log_msg
);
incoming_async_msg
.
fill_log_msg
(
incoming_log_msg
);
_formatter
->
format
(
incoming_log_msg
);
if
(
incoming_log_msg
.
level
==
level
::
off
)
{
_active
=
false
;
return
false
;
}
_formatter
->
format
(
incoming_log_msg
);
for
(
auto
&
s
:
_sinks
)
for
(
auto
&
s
:
_sinks
)
s
->
log
(
incoming_log_msg
);
s
->
log
(
incoming_log_msg
);
}
}
...
@@ -271,17 +282,7 @@ inline void spdlog::details::async_log_helper::throw_if_bad_worker()
...
@@ -271,17 +282,7 @@ inline void spdlog::details::async_log_helper::throw_if_bad_worker()
}
}
inline
void
spdlog
::
details
::
async_log_helper
::
join_worker
()
{
_active
=
false
;
try
{
_worker_thread
.
join
();
}
catch
(
const
std
::
system_error
&
)
//Dont crash if thread not joinable
{}
}
...
...
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