From 0ba583aa35bccf268e30dd03a6d423df5f98b40e Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 13 Feb 2016 16:30:08 +0100 Subject: Reimplement locking in `Logger::append` --- src/utility/logger.h | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'src/utility') diff --git a/src/utility/logger.h b/src/utility/logger.h index 49b7cc1..0dd88a6 100644 --- a/src/utility/logger.h +++ b/src/utility/logger.h @@ -15,25 +15,32 @@ class Logger { buffer_(target_fd, std::ios::out), stream_(&this->buffer_) { } - template - inline void append(Head&& head) { - this->stream_ << head << std::endl; - } + void forward(boost::process::pistream&); - template - inline void append(Head&& head, Tail&&... tail) { - this->stream_ << head; + template + void append(Arguments&&... args) { + std::lock_guard guard(this->write_mutex_); - this->append(std::forward(tail)...); + this->append_to_stream(std::forward(args)...); } - void forward(boost::process::pistream&); - private: __gnu_cxx::stdio_filebuf buffer_; std::ostream stream_; std::mutex write_mutex_; + template + inline void append_to_stream(Head&& head) { + this->stream_ << head << std::endl; + } + + template + inline void append_to_stream(Head&& head, Tail&&... tail) { + this->stream_ << head; + + this->append_to_stream(std::forward(tail)...); + } + }; } -- cgit v1.2.3