From 7bd54105e4b7fe950149719bf43dbad86702a2d0 Mon Sep 17 00:00:00 2001 From: Pavel Krajcevski Date: Sat, 28 Sep 2013 18:11:41 -0400 Subject: [PATCH] Add simple implementation of our thread-safe stream buffer. --- Core/include/ThreadSafeStreambuf.h | 2 ++ Core/src/ThreadSafeStreambuf.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/Core/include/ThreadSafeStreambuf.h b/Core/include/ThreadSafeStreambuf.h index 86689c4..a52f203 100644 --- a/Core/include/ThreadSafeStreambuf.h +++ b/Core/include/ThreadSafeStreambuf.h @@ -63,6 +63,8 @@ class ThreadSafeStreambuf : public ::std::streambuf { ThreadSafeStreambuf(); virtual ~ThreadSafeStreambuf(); + virtual std::streamsize xsputn(const char_type *s, std::streamsize count); + private: // Not implemented -- not allowed... ThreadSafeStreambuf(const ThreadSafeStreambuf &); diff --git a/Core/src/ThreadSafeStreambuf.cpp b/Core/src/ThreadSafeStreambuf.cpp index 06811be..319ebe5 100644 --- a/Core/src/ThreadSafeStreambuf.cpp +++ b/Core/src/ThreadSafeStreambuf.cpp @@ -68,4 +68,11 @@ ThreadSafeStreambuf::~ThreadSafeStreambuf() { } } +::std::streamsize ThreadSafeStreambuf::xsputn(const char_type *s, + ::std::streamsize count) { + // Lock it. + TCLock lock(*m_Mutex); + // then just do what you would have done... + return ::std::streambuf::xsputn(s, count); +}