From 0f083843bc31bf985991728125ef74efca6ef7b7 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 27 Dec 2015 10:07:24 +0100 Subject: Introduce thread synchronization for tracking init and logging This obviously leads to synchronizing syscalls that would otherwise happen in parallel. Luckily the goal of this library is to monitor file changes performed by single, user facing applications and as such it doesn't matter if some operations are slightly slower. --- src/utility/logger.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/utility') diff --git a/src/utility/logger.h b/src/utility/logger.h index e21f6fd..30a6b44 100644 --- a/src/utility/logger.h +++ b/src/utility/logger.h @@ -1,6 +1,8 @@ #ifndef CHANGE_SRC_LOGGER_H_ #define CHANGE_SRC_LOGGER_H_ +#include + #include #include @@ -14,6 +16,8 @@ class Logger { stream_(&this->buffer_) { } void append(const std::string& msg) { + std::lock_guard guard(this->write_mutex_); + this->stream_ << msg << std::endl; } @@ -25,6 +29,8 @@ class Logger { // flag. // void forward(boost::process::pistream& stream) { + std::lock_guard guard(this->write_mutex_); + this->stream_ << std::string( (std::istreambuf_iterator(stream)), (std::istreambuf_iterator()) @@ -34,6 +40,7 @@ class Logger { private: __gnu_cxx::stdio_filebuf buffer_; std::ostream stream_; + std::mutex write_mutex_; }; -- cgit v1.2.3