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
7ed8e1b5
Commit
7ed8e1b5
authored
Jul 07, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed async block policy
parent
4f1ce918
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
14 deletions
+14
-14
async.h
include/spdlog/async.h
+1
-1
async_logger.h
include/spdlog/async_logger.h
+3
-3
common.h
include/spdlog/common.h
+3
-2
thread_pool.h
include/spdlog/details/thread_pool.h
+2
-3
test_async.cpp
tests/test_async.cpp
+5
-5
No files found.
include/spdlog/async.h
View file @
7ed8e1b5
...
@@ -39,7 +39,7 @@ struct async_factory
...
@@ -39,7 +39,7 @@ struct async_factory
}
}
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
auto
sink
=
std
::
make_shared
<
Sink
>
(
std
::
forward
<
SinkArgs
>
(
args
)...);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
std
::
move
(
sink
),
std
::
move
(
tp
),
async_overflow_policy
::
block
_retry
);
auto
new_logger
=
std
::
make_shared
<
async_logger
>
(
logger_name
,
std
::
move
(
sink
),
std
::
move
(
tp
),
async_overflow_policy
::
block
);
registry
::
instance
().
register_and_init
(
new_logger
);
registry
::
instance
().
register_and_init
(
new_logger
);
return
new_logger
;
return
new_logger
;
}
}
...
...
include/spdlog/async_logger.h
View file @
7ed8e1b5
...
@@ -34,13 +34,13 @@ class async_logger SPDLOG_FINAL : public std::enable_shared_from_this<async_logg
...
@@ -34,13 +34,13 @@ class async_logger SPDLOG_FINAL : public std::enable_shared_from_this<async_logg
public
:
public
:
template
<
class
It
>
template
<
class
It
>
async_logger
(
const
std
::
string
&
logger_name
,
const
It
&
begin
,
const
It
&
end
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_logger
(
const
std
::
string
&
logger_name
,
const
It
&
begin
,
const
It
&
end
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
_retry
);
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
);
async_logger
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_logger
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
_retry
);
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
);
async_logger
(
const
std
::
string
&
logger_name
,
sink_ptr
single_sink
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_logger
(
const
std
::
string
&
logger_name
,
sink_ptr
single_sink
,
std
::
weak_ptr
<
details
::
thread_pool
>
tp
,
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
_retry
);
async_overflow_policy
overflow_policy
=
async_overflow_policy
::
block
);
protected
:
protected
:
void
sink_it_
(
details
::
log_msg
&
msg
)
override
;
void
sink_it_
(
details
::
log_msg
&
msg
)
override
;
...
...
include/spdlog/common.h
View file @
7ed8e1b5
...
@@ -63,6 +63,7 @@ using log_clock = std::chrono::system_clock;
...
@@ -63,6 +63,7 @@ using log_clock = std::chrono::system_clock;
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
spdlog
::
formatter
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
spdlog
::
formatter
>
;
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
using
level_t
=
details
::
null_atomic_int
;
using
level_t
=
details
::
null_atomic_int
;
#else
#else
...
@@ -126,8 +127,8 @@ using level_hasher = std::hash<int>;
...
@@ -126,8 +127,8 @@ using level_hasher = std::hash<int>;
//
//
enum
class
async_overflow_policy
enum
class
async_overflow_policy
{
{
block
_retry
,
// Block until message can be enqueued
block
,
// Block until message can be enqueued
overrun_oldes
et
// Discard oldest message in the queue if full when trying to add new item.
overrun_oldes
t
// Discard oldest message in the queue if full when trying to add new item.
};
};
//
//
...
...
include/spdlog/details/thread_pool.h
View file @
7ed8e1b5
...
@@ -106,14 +106,13 @@ public:
...
@@ -106,14 +106,13 @@ public:
{
{
for
(
size_t
i
=
0
;
i
<
threads_
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
threads_
.
size
();
i
++
)
{
{
post_async_msg_
(
async_msg
(
async_msg_type
::
terminate
),
async_overflow_policy
::
block
_retry
);
post_async_msg_
(
async_msg
(
async_msg_type
::
terminate
),
async_overflow_policy
::
block
);
}
}
for
(
auto
&
t
:
threads_
)
for
(
auto
&
t
:
threads_
)
{
{
t
.
join
();
t
.
join
();
}
}
// std::cout << "~thread_pool() msg_counter_: " << msg_counter_ << std::endl;
}
}
catch
(...)
catch
(...)
{
{
...
@@ -138,7 +137,7 @@ private:
...
@@ -138,7 +137,7 @@ private:
void
post_async_msg_
(
async_msg
&&
new_msg
,
async_overflow_policy
overflow_policy
)
void
post_async_msg_
(
async_msg
&&
new_msg
,
async_overflow_policy
overflow_policy
)
{
{
if
(
overflow_policy
==
async_overflow_policy
::
block
_retry
)
if
(
overflow_policy
==
async_overflow_policy
::
block
)
{
{
q_
.
enqueue
(
std
::
move
(
new_msg
));
q_
.
enqueue
(
std
::
move
(
new_msg
));
}
}
...
...
tests/test_async.cpp
View file @
7ed8e1b5
...
@@ -11,7 +11,7 @@ TEST_CASE("basic async test ", "[async]")
...
@@ -11,7 +11,7 @@ TEST_CASE("basic async test ", "[async]")
size_t
messages
=
256
;
size_t
messages
=
256
;
{
{
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
block
_retry
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
block
);
for
(
size_t
i
=
0
;
i
<
messages
;
i
++
)
for
(
size_t
i
=
0
;
i
<
messages
;
i
++
)
{
{
logger
->
info
(
"Hello message #{}"
,
i
);
logger
->
info
(
"Hello message #{}"
,
i
);
...
@@ -30,7 +30,7 @@ TEST_CASE("discard policy ", "[async]")
...
@@ -30,7 +30,7 @@ TEST_CASE("discard policy ", "[async]")
size_t
messages
=
1024
;
size_t
messages
=
1024
;
{
{
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
overrun_oldes
e
t
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
overrun_oldest
);
for
(
size_t
i
=
0
;
i
<
messages
;
i
++
)
for
(
size_t
i
=
0
;
i
<
messages
;
i
++
)
{
{
logger
->
info
(
"Hello message #{}"
,
i
);
logger
->
info
(
"Hello message #{}"
,
i
);
...
@@ -48,7 +48,7 @@ TEST_CASE("flush", "[async]")
...
@@ -48,7 +48,7 @@ TEST_CASE("flush", "[async]")
size_t
messages
=
256
;
size_t
messages
=
256
;
{
{
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
block
_retry
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
block
);
for
(
size_t
i
=
0
;
i
<
messages
;
i
++
)
for
(
size_t
i
=
0
;
i
<
messages
;
i
++
)
{
{
logger
->
info
(
"Hello message #{}"
,
i
);
logger
->
info
(
"Hello message #{}"
,
i
);
...
@@ -69,7 +69,7 @@ TEST_CASE("tp->wait_empty() ", "[async]")
...
@@ -69,7 +69,7 @@ TEST_CASE("tp->wait_empty() ", "[async]")
size_t
messages
=
100
;
size_t
messages
=
100
;
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
messages
,
2
);
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
messages
,
2
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
block
_retry
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
block
);
for
(
size_t
i
=
0
;
i
<
messages
;
i
++
)
for
(
size_t
i
=
0
;
i
<
messages
;
i
++
)
{
{
logger
->
info
(
"Hello message #{}"
,
i
);
logger
->
info
(
"Hello message #{}"
,
i
);
...
@@ -90,7 +90,7 @@ TEST_CASE("multi threads", "[async]")
...
@@ -90,7 +90,7 @@ TEST_CASE("multi threads", "[async]")
size_t
n_threads
=
10
;
size_t
n_threads
=
10
;
{
{
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
tp
=
std
::
make_shared
<
details
::
thread_pool
>
(
queue_size
,
1
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
block
_retry
);
auto
logger
=
std
::
make_shared
<
async_logger
>
(
"as"
,
test_sink
,
tp
,
async_overflow_policy
::
block
);
std
::
vector
<
std
::
thread
>
threads
;
std
::
vector
<
std
::
thread
>
threads
;
for
(
size_t
i
=
0
;
i
<
n_threads
;
i
++
)
for
(
size_t
i
=
0
;
i
<
n_threads
;
i
++
)
...
...
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