From ca620cc62c5ebd702f1a825f1329e34a69382a3a Mon Sep 17 00:00:00 2001 From: bangerth Date: Wed, 24 Apr 2013 14:49:17 +0000 Subject: [PATCH] Set stream properties only once, rather than every time we access the stream. git-svn-id: https://svn.dealii.org/trunk@29381 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/logstream.h | 33 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/deal.II/include/deal.II/base/logstream.h b/deal.II/include/deal.II/base/logstream.h index f226012574..574cc5309a 100644 --- a/deal.II/include/deal.II/base/logstream.h +++ b/deal.II/include/deal.II/base/logstream.h @@ -563,25 +563,42 @@ private: * function will return the correct internal ostringstream buffer for * operater<<. */ - std::ostringstream &get_stream() - { - // ??? why the following? - outstreams.get().setf(std::ios::showpoint | std::ios::left); - return outstreams.get(); - } + std::ostringstream &get_stream(); /** * We use tbb's thread local storage facility to generate a stringstream * for every thread that sends log messages. */ - Threads::ThreadLocalStorage outstreams; - + Threads::ThreadLocalStorage > outstreams; }; /* ----------------------------- Inline functions and templates ---------------- */ +inline +std::ostringstream & +LogStream::get_stream() +{ + // see if we have already created this stream. if not, do so and + // set the default flags (why we set these flags is lost to + // history, but this is what we need to keep several hundred tests + // from producing different output) + // + // note that in all of this we need not worry about thread-safety + // because we operate on a thread-local object and by definition + // there can only be one access at a time + if (outstreams.get() == 0) + { + outstreams.get().reset (new std::ostringstream); + outstreams.get()->setf(std::ios::showpoint | std::ios::left); + } + + // then return the stream + return *outstreams.get(); +} + + template inline LogStream & -- 2.39.5