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
06fb5c7c
Commit
06fb5c7c
authored
Jun 19, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close issue #1113
parent
8970fd5d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
thread_pool-inl.h
include/spdlog/details/thread_pool-inl.h
+13
-2
thread_pool.h
include/spdlog/details/thread_pool.h
+3
-0
No files found.
include/spdlog/details/thread_pool-inl.h
View file @
06fb5c7c
...
...
@@ -11,7 +11,8 @@
namespace
spdlog
{
namespace
details
{
SPDLOG_INLINE
thread_pool
::
thread_pool
(
size_t
q_max_items
,
size_t
threads_n
)
SPDLOG_INLINE
thread_pool
::
thread_pool
(
size_t
q_max_items
,
size_t
threads_n
,
std
::
function
<
void
()
>
on_thread_start
)
:
q_
(
q_max_items
)
{
if
(
threads_n
==
0
||
threads_n
>
1000
)
...
...
@@ -21,10 +22,20 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
}
for
(
size_t
i
=
0
;
i
<
threads_n
;
i
++
)
{
threads_
.
emplace_back
(
&
thread_pool
::
worker_loop_
,
this
);
threads_
.
emplace_back
([
this
,
on_thread_start
]
{
on_thread_start
();
this
->
thread_pool
::
worker_loop_
();
});
}
}
SPDLOG_INLINE
thread_pool
::
thread_pool
(
size_t
q_max_items
,
size_t
threads_n
)
:
thread_pool
(
q_max_items
,
threads_n
,
[]{})
{
}
// message all threads to terminate gracefully join them
SPDLOG_INLINE
thread_pool
::~
thread_pool
()
{
...
...
include/spdlog/details/thread_pool.h
View file @
06fb5c7c
...
...
@@ -11,6 +11,7 @@
#include <memory>
#include <thread>
#include <vector>
#include <functional>
namespace
spdlog
{
class
async_logger
;
...
...
@@ -118,7 +119,9 @@ public:
using
item_type
=
async_msg
;
using
q_type
=
details
::
mpmc_blocking_queue
<
item_type
>
;
thread_pool
(
size_t
q_max_items
,
size_t
threads_n
,
std
::
function
<
void
()
>
on_thread_start
);
thread_pool
(
size_t
q_max_items
,
size_t
threads_n
);
// message all threads to terminate gracefully join them
~
thread_pool
();
...
...
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