]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Set stream properties only once, rather than every time we access the stream.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 24 Apr 2013 14:49:17 +0000 (14:49 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 24 Apr 2013 14:49:17 +0000 (14:49 +0000)
git-svn-id: https://svn.dealii.org/trunk@29381 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/logstream.h

index f22601257441796d44e7ff7b44fb88e3cf6bffd8..574cc5309a952499ab1556e3133027689a257e66 100644 (file)
@@ -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<std::ostringstream> outstreams;
-
+  Threads::ThreadLocalStorage<std_cxx1x::shared_ptr<std::ostringstream> > 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 <class T>
 inline
 LogStream &

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.