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 | |
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`
-rw-r--r-- | src/change_log.cc | 20 | ||||
-rw-r--r-- | src/utility/logger.h | 27 |
2 files changed, 25 insertions, 22 deletions
diff --git a/src/change_log.cc b/src/change_log.cc index 8ff99e4..ae28079 100644 --- a/src/change_log.cc +++ b/src/change_log.cc @@ -1,7 +1,3 @@ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include "actual_function.h" #include "utility/io.h" @@ -83,6 +79,14 @@ ssize_t writev(int fd, const iovec* iov, int iovcnt) { return actual::writev(fd, iov, iovcnt); } +void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) { + if ( prot & PROT_WRITE ) { + track_write(fd); + } + + return actual::mmap(addr, length, prot, flags, fd, offset); +} + int rename(const char* old_path, const char* new_path) { track_rename(old_path, new_path); @@ -110,11 +114,3 @@ int unlinkat(int dirfd, const char* path, int flags) { return actual::unlinkat(dirfd, path, flags); } - -void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) { - if ( prot & PROT_WRITE ) { - track_write(fd); - } - - return actual::mmap(addr, length, prot, flags, fd, offset); -} 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)...); + } + }; } |