]> https://gitweb.dealii.org/ - dealii.git/commitdiff
port LogStream to the new ThreadLocalStorage
authorMatthias Maier <tamiko@43-1.org>
Tue, 26 May 2020 22:53:25 +0000 (17:53 -0500)
committerMatthias Maier <tamiko@43-1.org>
Wed, 27 May 2020 16:26:14 +0000 (11:26 -0500)
include/deal.II/base/logstream.h
include/deal.II/base/thread_local_storage.h
source/base/logstream.cc

index 15f137dfb8f7f4a44e2ce2ee02ff2679b51b609e..ffe5bd9e1d0fff827b0c4b1f236e6de0b2528db8 100644 (file)
@@ -321,6 +321,13 @@ private:
    */
   mutable Threads::ThreadLocalStorage<std::stack<std::string>> prefixes;
 
+  /**
+   * We record the thread id of the thread creating this object. We need
+   * this information to "steal" the current prefix from this "master"
+   * thread on first use of deallog on a new thread.
+   */
+  std::thread::id master_thread;
+
   /**
    * Default stream, where the output is to go to. This stream defaults to
    * <tt>std::cout</tt>, but can be set to another stream through the
@@ -373,7 +380,7 @@ private:
   get_stream();
 
   /**
-   * We use tbb's thread local storage facility to generate a stringstream for
+   * We use our thread local storage facility to generate a stringstream for
    * every thread that sends log messages.
    */
   Threads::ThreadLocalStorage<std::shared_ptr<std::ostringstream>> outstreams;
index 216def42fc75abb6916fd7c716ba688ac6dfc29e..5b3691ab3c3f0d1b8c490c20dbaa184f1ea8bc08 100644 (file)
@@ -31,6 +31,9 @@ DEAL_II_NAMESPACE_OPEN
 /*!@addtogroup threads */
 /*@{*/
 
+#  ifndef DOXYGEN
+class LogStream;
+#  endif
 
 namespace Threads
 {
@@ -216,6 +219,8 @@ namespace Threads
      * An exemplar for creating a new (thread specific) copy.
      */
     std::shared_ptr<const T> exemplar;
+
+    friend class dealii::LogStream;
   };
 } // namespace Threads
 /**
index 785259e26ff649557b12d3aff40f0db5726b79b1..5cceadf762f0b25774537fbbcfbc45829694eec4 100644 (file)
@@ -73,7 +73,8 @@ LogStream::Prefix::~Prefix()
 
 
 LogStream::LogStream()
-  : std_out(&std::cout)
+  : master_thread(std::this_thread::get_id())
+  , std_out(&std::cout)
   , file(nullptr)
   , std_depth(0)
   , file_depth(10000)
@@ -385,25 +386,14 @@ LogStream::get_prefixes() const
   bool                     exists         = false;
   std::stack<std::string> &local_prefixes = prefixes.get(exists);
 
-#  if 0 // FIXME
   // If this is a new locally stored stack, copy the "blessed" prefixes
   // from the initial thread that created logstream.
   if (!exists)
     {
-      const tbb::enumerable_thread_specific<std::stack<std::string>> &impl =
-        prefixes.get_implementation();
-
-      // The thread that created this LogStream object should be the first
-      // in tbb's enumerable_thread_specific container.
-      const tbb::enumerable_thread_specific<
-        std::stack<std::string>>::const_iterator first_elem = impl.begin();
-
-      if (first_elem != impl.end())
-        {
-          local_prefixes = *first_elem;
-        }
+      auto it = prefixes.data.find(master_thread);
+      if (it != prefixes.data.end())
+        local_prefixes = it->second;
     }
-#  endif
 
   return local_prefixes;
 

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.