00001 //--------------------------------------------------------------------------- 00002 // @f$Id: thread_local_storage.h 25345 2012-03-31 08:37:04Z bangerth @f$ 00003 // 00004 // Copyright (C) 2011, 2012 by the deal.II authors 00005 // 00006 // This file is subject to QPL and may not be distributed 00007 // without copyright and license information. Please refer 00008 // to the file deal.II/doc/license.html for the text and 00009 // further information on this license. 00010 // 00011 //--------------------------------------------------------------------------- 00012 #ifndef __deal2__thread_local_storage_h 00013 #define __deal2__thread_local_storage_h 00014 00015 00016 #include <deal.II/base/config.h> 00017 00018 #if DEAL_II_USE_MT == 1 00019 # include <tbb/enumerable_thread_specific.h> 00020 #endif 00021 00022 00023 00024 DEAL_II_NAMESPACE_OPEN 00025 00028 00029 00030 namespace Threads 00031 { 00032 template <typename T> 00064 class ThreadLocalStorage 00065 { 00066 public: 00071 ThreadLocalStorage (); 00072 00077 explicit ThreadLocalStorage (const T &t); 00078 00083 ThreadLocalStorage (const ThreadLocalStorage<T> &t); 00084 00099 T & get (); 00100 00107 operator T & (); 00108 00121 ThreadLocalStorage<T> & operator = (const T &t); 00122 00123 private: 00124 #if DEAL_II_USE_MT == 1 00125 00131 tbb::enumerable_thread_specific<T> data; 00132 #else 00133 T data; 00134 #endif 00135 }; 00136 00137 // ----------------- inline and template functions ---------------------------- 00138 00139 template <typename T> 00140 inline 00141 ThreadLocalStorage<T>::ThreadLocalStorage() 00142 {} 00143 00144 00145 template <typename T> 00146 inline 00147 ThreadLocalStorage<T>::ThreadLocalStorage(const T &t) 00148 : 00149 data (t) 00150 {} 00151 00152 00153 template <typename T> 00154 inline 00155 ThreadLocalStorage<T>::ThreadLocalStorage(const ThreadLocalStorage<T> &t) 00156 : 00157 data (t) 00158 {} 00159 00160 00161 template <typename T> 00162 inline 00163 T & 00164 ThreadLocalStorage<T>::get () 00165 { 00166 #if DEAL_II_USE_MT == 1 00167 return data.local(); 00168 #else 00169 return data; 00170 #endif 00171 } 00172 00173 00174 00175 template <typename T> 00176 inline 00177 ThreadLocalStorage<T>::operator T& () 00178 { 00179 return get(); 00180 } 00181 00182 00183 template <typename T> 00184 inline 00185 ThreadLocalStorage<T> & 00186 ThreadLocalStorage<T>::operator = (const T &t) 00187 { 00188 get() = t; 00189 return *this; 00190 } 00191 } // end of implementation of namespace Threads 00192 00198 //--------------------------------------------------------------------------- 00199 DEAL_II_NAMESPACE_CLOSE 00200 // end of #ifndef __deal2__thread_local_storage_h 00201 #endif 00202 //--------------------------------------------------------------------------- 00203
documentation generated on Wed May 23 2012 12:03:22 by
doxygen
1.7.3