Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
67ddd597
Commit
67ddd597
authored
Apr 28, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move msg and remove spinning
parent
78ea362e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
19 deletions
+6
-19
thread_pool.h
include/spdlog/details/thread_pool.h
+6
-19
No files found.
include/spdlog/details/thread_pool.h
View file @
67ddd597
...
@@ -78,7 +78,7 @@ struct async_msg
...
@@ -78,7 +78,7 @@ struct async_msg
}
}
// copy into log_msg
// copy into log_msg
void
to_log_msg
(
log_msg
&
msg
)
void
to_log_msg
(
log_msg
&
&
msg
)
{
{
msg
.
logger_name
=
&
worker_ptr
->
name
();
msg
.
logger_name
=
&
worker_ptr
->
name
();
msg
.
level
=
level
;
msg
.
level
=
level
;
...
@@ -151,14 +151,7 @@ public:
...
@@ -151,14 +151,7 @@ public:
return
_msg_counter
.
load
(
std
::
memory_order_relaxed
);
return
_msg_counter
.
load
(
std
::
memory_order_relaxed
);
}
}
void
wait_empty_q
()
{
auto
last_op
=
clock_type
::
now
();
while
(
!
_q
.
is_empty
())
{
sleep_or_yield
(
clock_type
::
now
(),
last_op
);
}
}
private
:
private
:
std
::
atomic
<
size_t
>
_msg_counter
;
// total # of messages processed in this pool
std
::
atomic
<
size_t
>
_msg_counter
;
// total # of messages processed in this pool
...
@@ -208,7 +201,7 @@ private:
...
@@ -208,7 +201,7 @@ private:
default:
default:
{
{
popped_async_msg
.
to_log_msg
(
msg
);
popped_async_msg
.
to_log_msg
(
std
::
move
(
msg
)
);
auto
worker
=
std
::
move
(
popped_async_msg
.
worker_ptr
);
auto
worker
=
std
::
move
(
popped_async_msg
.
worker_ptr
);
worker
->
_backend_log
(
msg
);
worker
->
_backend_log
(
msg
);
_msg_counter
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
_msg_counter
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
...
@@ -229,18 +222,12 @@ private:
...
@@ -229,18 +222,12 @@ private:
using
std
::
chrono
::
milliseconds
;
using
std
::
chrono
::
milliseconds
;
auto
time_since_op
=
now
-
last_op_time
;
auto
time_since_op
=
now
-
last_op_time
;
// spin upto 50 micros
if
(
time_since_op
<=
microseconds
(
50
))
{
return
;
}
// yield upto 150 micros
// yield upto 150 micros
if
(
time_since_op
<=
microseconds
(
1
0
0
))
if
(
time_since_op
<=
microseconds
(
1
5
0
))
{
{
return
std
::
this_thread
::
yield
();
return
std
::
this_thread
::
yield
();
}
}
// sleep for 20 ms upto 200 ms
// sleep for 20 ms upto 200 ms
if
(
time_since_op
<=
milliseconds
(
200
))
if
(
time_since_op
<=
milliseconds
(
200
))
...
...
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