From: Matthias Maier Date: Tue, 26 May 2020 22:53:25 +0000 (-0500) Subject: port LogStream to the new ThreadLocalStorage X-Git-Tag: v9.3.0-rc1~1535^2~6 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c491aa46b214116fcd4e055f1412c125a411816;p=dealii.git port LogStream to the new ThreadLocalStorage --- diff --git a/include/deal.II/base/logstream.h b/include/deal.II/base/logstream.h index 15f137dfb8..ffe5bd9e1d 100644 --- a/include/deal.II/base/logstream.h +++ b/include/deal.II/base/logstream.h @@ -321,6 +321,13 @@ private: */ mutable Threads::ThreadLocalStorage> 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 * std::cout, 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> outstreams; diff --git a/include/deal.II/base/thread_local_storage.h b/include/deal.II/base/thread_local_storage.h index 216def42fc..5b3691ab3c 100644 --- a/include/deal.II/base/thread_local_storage.h +++ b/include/deal.II/base/thread_local_storage.h @@ -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 exemplar; + + friend class dealii::LogStream; }; } // namespace Threads /** diff --git a/source/base/logstream.cc b/source/base/logstream.cc index 785259e26f..5cceadf762 100644 --- a/source/base/logstream.cc +++ b/source/base/logstream.cc @@ -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 &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> &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>::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;