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
133ce994
Commit
133ce994
authored
Mar 30, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
async_sink
parent
28e1c659
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
14 deletions
+13
-14
example.cpp
example/example.cpp
+4
-3
async_sink.h
include/c11log/sinks/async_sink.h
+9
-11
No files found.
example/example.cpp
View file @
133ce994
...
...
@@ -35,13 +35,14 @@ int main(int argc, char* argv[])
for
(
unsigned
int
i
=
1
;
i
<=
howmany
;
++
i
)
my_logger
.
info
()
<<
"Hello logger: "
<<
i
;
as
->
shutdown
(
milliseconds
(
500
));
//as->shutdown(milliseconds(500));
auto
s
=
howmany
-
as
->
q
().
size
();
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout_logger
.
info
()
<<
"Total:"
<<
format
(
howmany
);
cout_logger
.
info
()
<<
"Total:"
<<
format
(
s
);
cout_logger
.
info
()
<<
"Delta:"
<<
format
(
delta_d
);
cout_logger
.
info
()
<<
"Rate:"
<<
format
(
howmany
/
delta_d
)
<<
"/sec"
;
cout_logger
.
info
()
<<
"Rate:"
<<
format
(
s
/
delta_d
)
<<
"/sec"
;
return
0
;
}
...
...
include/c11log/sinks/async_sink.h
View file @
133ce994
...
...
@@ -38,7 +38,7 @@ public:
~
async_sink
();
void
add_sink
(
logger
::
sink_ptr
sink
);
void
remove_sink
(
logger
::
sink_ptr
sink_ptr
);
queue_type
&
q
();
//Wait to remaining items (if any) in the queue to be written and shutdown
void
shutdown
(
const
std
::
chrono
::
milliseconds
&
timeout
);
...
...
@@ -82,20 +82,13 @@ inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
if
(
!
_active
||
!
msg_size
)
return
;
//re allocate on the heap the (stack based) message
auto
new_msg
=
new
details
::
log_msg
();
*
new_msg
=
msg
;
auto
new_msg
=
new
details
::
log_msg
(
msg
);
char
*
buf
=
new
char
[
msg_size
];
std
::
memcpy
(
buf
,
msg
.
msg_buf
.
first
,
msg_size
);
new_msg
->
msg_buf
=
bufpair_t
(
buf
,
msg_size
);
/*
auto new_shared_msg = queue_type::item_type(new_msg, [](const details::log_msg* msg_to_delete)
{
delete []msg_to_delete->msg_buf.first;
delete msg_to_delete;
});
* */
queue_type
::
item_type
new_shared_msg
(
new_msg
,
msg_deleter
);
// Create unique_ptr with custom deleter and push it
queue_type
::
item_type
new_shared_msg
(
new_msg
,
msg_deleter
);
_q
.
push
(
std
::
move
(
new_shared_msg
));
}
...
...
@@ -127,6 +120,11 @@ inline void c11log::sinks::async_sink::remove_sink(logger::sink_ptr sink_ptr)
_sinks
.
erase
(
std
::
remove
(
_sinks
.
begin
(),
_sinks
.
end
(),
sink_ptr
),
_sinks
.
end
());
}
inline
c11log
::
sinks
::
async_sink
::
queue_type
&
c11log
::
sinks
::
async_sink
::
q
()
{
return
_q
;
}
inline
void
c11log
::
sinks
::
async_sink
::
shutdown
(
const
std
::
chrono
::
milliseconds
&
timeout
)
{
...
...
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