From: bangerth Date: Fri, 7 Feb 2014 01:04:47 +0000 (+0000) Subject: Provide ThreadLocalStorage::clear(). X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6fed803bc773f19b02a1ac67cb902f388670054;p=dealii-svn.git Provide ThreadLocalStorage::clear(). git-svn-id: https://svn.dealii.org/trunk@32428 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index c99951908f..0126d3df68 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -124,6 +124,11 @@ inconvenience this causes.

Specific improvements

    +
  1. New: ThreadLocalStorage::clear() clears out all objects allocated on the + current and all other threads. +
    + (Wolfgang Bangerth, 2014/02/06) +
  2. Fixed: A configuration error on Debian Testing where accidentally a non-pic libSuiteSparse_config.a was picked up when building a shared library up resulting in a link error. diff --git a/deal.II/include/deal.II/base/thread_local_storage.h b/deal.II/include/deal.II/base/thread_local_storage.h index dccaa2f61f..70d71b75ed 100644 --- a/deal.II/include/deal.II/base/thread_local_storage.h +++ b/deal.II/include/deal.II/base/thread_local_storage.h @@ -1,7 +1,7 @@ // --------------------------------------------------------------------- // $Id$ // -// Copyright (C) 2011 - 2013 by the deal.II authors +// Copyright (C) 2011 - 2014 by the deal.II authors // // This file is part of the deal.II library. // @@ -84,7 +84,7 @@ namespace Threads /** * Copy constructor. Initialize each thread local object * with the corresponding object of the given object. - **/ + */ ThreadLocalStorage (const ThreadLocalStorage &t); /** @@ -132,17 +132,37 @@ namespace Threads ThreadLocalStorage &operator = (const T &t); /** - * Returns a reference to the internal implementation. + * Remove the thread-local objects stored for all threads that have + * created one with this object (i.e., that have called get() + * at least once on this thread. This includes the current thread. If you + * call get() subsequently on this or any other thread, new objects will + * again be created. + * + * If deal.II has been configured to not use multithreading, then this function + * does not do anything at all. Note that this of course has different semantics + * as in the multithreading context the objects are deleted and created again + * (possible by copying from a sample object, if the appropriate constructor + * of this class was called), whereas in the multithreaded context the object + * is simply not touched at all. At the same time, the purpose of this function + * is to release memory other threads may have allocated for their own thread + * local objects after which every use of this object will require some kind + * of initialization. This is necessary both in the multithreaded or + * non-multithreaded case. + */ + void clear (); + + /** + * Returns a reference to the internal Threading Building Blocks + * implementation. This function is really only useful if deal.II + * has been configured with multithreading and has no useful + * purpose otherwise. */ #ifdef DEAL_II_WITH_THREADS tbb::enumerable_thread_specific & #else T & #endif - get_implementation() - { - return data; - } + get_implementation(); private: #ifdef DEAL_II_WITH_THREADS @@ -225,6 +245,31 @@ namespace Threads get() = t; return *this; } + + + template + inline +#ifdef DEAL_II_WITH_THREADS + tbb::enumerable_thread_specific & +#else + T & +#endif + ThreadLocalStorage::get_implementation() + { + return data; + } + + + + template + inline + void + ThreadLocalStorage::clear () + { +#ifdef DEAL_II_WITH_THREADS + data.clear (); +#endif + } } // end of implementation of namespace Threads /**