diff options
author | Adrian Kummerlaender | 2016-02-13 16:30:08 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-02-13 16:30:08 +0100 |
commit | 0ba583aa35bccf268e30dd03a6d423df5f98b40e (patch) | |
tree | 2f3f52b33e4ec42663f0da2ddca2c3d817820969 /src/utility | |
parent | 7582ab165b4c57d2325561b59d99a6665af28cc3 (diff) | |
download | change-0ba583aa35bccf268e30dd03a6d423df5f98b40e.tar change-0ba583aa35bccf268e30dd03a6d423df5f98b40e.tar.gz change-0ba583aa35bccf268e30dd03a6d423df5f98b40e.tar.bz2 change-0ba583aa35bccf268e30dd03a6d423df5f98b40e.tar.lz change-0ba583aa35bccf268e30dd03a6d423df5f98b40e.tar.xz change-0ba583aa35bccf268e30dd03a6d423df5f98b40e.tar.zst change-0ba583aa35bccf268e30dd03a6d423df5f98b40e.zip |
Reimplement locking in `Logger::append`
Diffstat (limited to 'src/utility')
-rw-r--r-- | src/utility/logger.h | 27 |
1 files changed, 17 insertions, 10 deletions
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 <typename Head> - inline void append(Head&& head) { - this->stream_ << head << std::endl; - } + void forward(boost::process::pistream&); - template <typename Head, typename... Tail> - inline void append(Head&& head, Tail&&... tail) { - this->stream_ << head; + template <typename... Arguments> + void append(Arguments&&... args) { + std::lock_guard<std::mutex> guard(this->write_mutex_); - this->append(std::forward<Tail>(tail)...); + this->append_to_stream(std::forward<Arguments>(args)...); } - void forward(boost::process::pistream&); - private: __gnu_cxx::stdio_filebuf<char> buffer_; std::ostream stream_; std::mutex write_mutex_; + template <typename Head> + inline void append_to_stream(Head&& head) { + this->stream_ << head << std::endl; + } + + template <typename Head, typename... Tail> + inline void append_to_stream(Head&& head, Tail&&... tail) { + this->stream_ << head; + + this->append_to_stream(std::forward<Tail>(tail)...); + } + }; } |