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
b943265b
Commit
b943265b
authored
Dec 02, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better handling of empty queue
parent
243dc61e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
3 deletions
+31
-3
include/spdlog/details/async_log_helper.h
include/spdlog/details/async_log_helper.h
+31
-3
No files found.
include/spdlog/details/async_log_helper.h
View file @
b943265b
...
...
@@ -87,6 +87,8 @@ class async_log_helper
public:
using
q_type
=
details
::
mpsc_q
<
std
::
unique_ptr
<
async_msg
>
>
;
using
clock
=
std
::
chrono
::
monotonic_clock
;
explicit
async_log_helper
(
size_t
max_queue_size
);
void
log
(
const
details
::
log_msg
&
msg
);
...
...
@@ -116,12 +118,17 @@ private:
// worker thread formatter
formatter_ptr
_formatter
;
// will throw last back thread exception or if worker hread no active
void
_push_sentry
();
// worker thread loop
void
_thread_loop
();
// guess how much to sleep if queue is empty
static
clock
::
duration
spdlog
::
details
::
async_log_helper
::
_calc_pop_sleep
(
const
clock
::
time_point
&
last_pop
);
// clear all remaining messages(if any), stop the _worker_thread and join it
void
_join
();
...
...
@@ -154,15 +161,18 @@ inline void spdlog::details::async_log_helper::log(const details::log_msg& msg)
inline
void
spdlog
::
details
::
async_log_helper
::
_thread_loop
()
{
clock
::
time_point
last_pop
=
clock
::
now
();
while
(
_active
)
{
q_type
::
item_type
async_msg
;
if
(
_q
.
pop
(
async_msg
))
{
last_pop
=
clock
::
now
();
try
{
details
::
log_msg
log_msg
=
async_msg
->
to_log_msg
();
_formatter
->
format
(
log_msg
);
...
...
@@ -179,13 +189,31 @@ inline void spdlog::details::async_log_helper::_thread_loop()
_last_workerthread_ex
=
std
::
make_shared
<
spdlog_ex
>
(
"Unknown exception"
);
}
}
else
//Sleep and retry if empty
//Sleep for a while if empty.
else
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
microseconds
(
100
));
std
::
this_thread
::
sleep_for
(
_calc_pop_sleep
(
last_pop
));
}
}
}
//Try to guess sleep duration according to the time passed since last message
inline
spdlog
::
details
::
async_log_helper
::
clock
::
duration
spdlog
::
details
::
async_log_helper
::
_calc_pop_sleep
(
const
clock
::
time_point
&
last_pop
)
{
using
std
::
chrono
::
milliseconds
;
using
std
::
chrono
::
microseconds
;
auto
time_since_pop
=
clock
::
now
()
-
last_pop
;
if
(
time_since_pop
>
milliseconds
(
1000
))
return
milliseconds
(
500
);
if
(
time_since_pop
>
microseconds
(
0
))
return
(
time_since_pop
/
2
);
return
microseconds
(
0
);
}
inline
void
spdlog
::
details
::
async_log_helper
::
add_sink
(
spdlog
::
sink_ptr
s
)
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
_mutex
);
...
...
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