18 #include "libmesh/thread_buffered_syncbuf.h" 19 #include "libmesh/threads.h" 24 : _sink(sink), _flush_on_newline(flush_on_newline), _mu(
std::make_unique<Threads::
spin_mutex>())
32 if (traits_type::eq_int_type(ch, traits_type::eof()))
33 return traits_type::not_eof(ch);
36 t.buf.push_back(traits_type::to_char_type(ch));
47 t.buf.append(s, static_cast<size_t>(n));
73 Threads::spin_mutex::scoped_lock lk(*
_mu);
80 Threads::spin_mutex::scoped_lock lk(*
_mu);
81 _sink.sputn(b.data(),
static_cast<std::streamsize
>(b.size()));
ThreadBufferedSyncbuf(std::streambuf &sink, bool flush_on_newline=true)
const bool _flush_on_newline
Whether to flush our sink to terminal/file on terminating new-line characters ( ) ...
The libMesh namespace provides an interface to certain functionality in the library.
ThreadLocalBuffer & thread_local_buffer()
One ThreadLocalBuffer instance per thread, constructed on first use with *this.
void emit_from_thread_local_buffer(std::string &b, bool force_flush)
Emit from the thread local buffer to our wrapped _sink.
~ThreadLocalBuffer()
Ensures we write to our sink upon destruction if our buf is non-empty.
std::streambuf & _sink
Wrapped output sink.
std::unique_ptr< Threads::spin_mutex > _mu
Serialization for commits to the shared sink.
int_type overflow(int_type ch) override
ThreadBufferedSyncbuf & _owner
owning syncing stream buffer
~ThreadBufferedSyncbuf()
Defaulted destructor defined in implementation so we don't need to include threads.h.
std::streamsize xsputn(const char *s, std::streamsize n) override
tbb::spin_mutex spin_mutex
Spin mutex.
std::string buf
per-thread buffer
A class that wraps a thread-local string.