Add simple implementation of our thread-safe stream buffer.

This commit is contained in:
Pavel Krajcevski 2013-09-28 18:11:41 -04:00
parent 8bc81edf14
commit 7bd54105e4
2 changed files with 9 additions and 0 deletions

View File

@ -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 &);

View File

@ -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);
}