Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
thread_local_storage.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2011 - 2020 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_thread_local_storage_h
17 # define dealii_thread_local_storage_h
18 
19 
20 # include <deal.II/base/config.h>
21 
23 # ifdef DEAL_II_WITH_THREADS
24 # include <tbb/enumerable_thread_specific.h>
25 # endif
27 
28 
29 
31 
34 
35 
36 namespace Threads
37 {
71  template <typename T>
73  {
74  public:
79  ThreadLocalStorage() = default;
80 
85  explicit ThreadLocalStorage(const T &t);
86 
92 
106  T &
107  get();
108 
113  T &
114  get(bool &exists);
115 
122  operator T &();
123 
137  operator=(const T &t);
138 
158  void
159  clear();
160 
166 # ifdef DEAL_II_WITH_THREADS
167  tbb::enumerable_thread_specific<T> &
168 # else
169  T &
170 # endif
172 
173  private:
174 # ifdef DEAL_II_WITH_THREADS
175 
180  tbb::enumerable_thread_specific<T> data;
181 # else
182  T data;
183 # endif
184  };
185 } // namespace Threads
190 # ifndef DOXYGEN
191 namespace Threads
192 {
193  // ----------------- inline and template functions --------------------------
194 
195  template <typename T>
197  : data(t)
198  {}
199 
200 
201  template <typename T>
203  const ThreadLocalStorage<T> &t)
204  : data(t)
205  {}
206 
207 
208  template <typename T>
209  inline T &
211  {
212 # ifdef DEAL_II_WITH_THREADS
213  return data.local();
214 # else
215  return data;
216 # endif
217  }
218 
219 
220  template <typename T>
221  inline T &
222  ThreadLocalStorage<T>::get(bool &exists)
223  {
224 # ifdef DEAL_II_WITH_THREADS
225  return data.local(exists);
226 # else
227  exists = true;
228  return data;
229 # endif
230  }
231 
232 
233  template <typename T>
235  {
236  return get();
237  }
238 
239 
240  template <typename T>
241  inline ThreadLocalStorage<T> &
243  {
244  get() = t;
245  return *this;
246  }
247 
248 
249  template <typename T>
250  inline
251 # ifdef DEAL_II_WITH_THREADS
252  tbb::enumerable_thread_specific<T> &
253 # else
254  T &
255 # endif
257  {
258  return data;
259  }
260 
261 
262 
263  template <typename T>
264  inline void
266  {
267 # ifdef DEAL_II_WITH_THREADS
268  data.clear();
269 # else
270  data = T{};
271 # endif
272  }
273 } // namespace Threads
274 
275 # endif // DOXYGEN
276 
277 //---------------------------------------------------------------------------
279 // end of #ifndef dealii_thread_local_storage_h
280 #endif
281 //---------------------------------------------------------------------------
A class that provides a separate storage location on each thread that accesses the object...
ThreadLocalStorage< T > & operator=(const T &t)
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition: config.h:372
static const char T
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
tbb::enumerable_thread_specific< T > & get_implementation()
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition: config.h:409
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
tbb::enumerable_thread_specific< T > data