Lunchbox  1.17.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
perThread.ipp
1 
2 /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 namespace lunchbox
19 {
20 template <class T, void (*D)(T*)>
22  : tls_((TLS::ThreadDestructor_t)D)
23 {
24 }
25 
26 template <class T, void (*D)(T*)>
28 {
29 }
30 
31 template <class T, void (*D)(T*)>
33 {
34  tls_.set(static_cast<const void*>(data));
35  return *this;
36 }
37 
38 template <class T, void (*D)(T*)>
40 {
41  tls_.set(rhs.tls_.get());
42  return *this;
43 }
44 
45 template <class T, void (*D)(T*)>
47 {
48  return static_cast<T*>(tls_.get());
49 }
50 
51 template <class T, void (*D)(T*)>
52 const T* PerThread<T, D>::get() const
53 {
54  return static_cast<const T*>(tls_.get());
55 }
56 
57 template <class T, void (*D)(T*)>
59 {
60  return static_cast<T*>(tls_.get());
61 }
62 
63 template <class T, void (*D)(T*)>
65 {
66  return static_cast<T*>(tls_.get());
67 }
68 
69 template <class T, void (*D)(T*)>
71 {
72  return tls_.get() == 0;
73 }
74 
75 template <class T, void (*D)(T*)>
77 {
78  return tls_.get() != 0;
79 }
80 }
PerThread()
Construct a new per-thread variable.
Definition: perThread.ipp:21
void * get()
bool isValid() const
Definition: perThread.ipp:76
bool operator!() const
Definition: perThread.ipp:70
PerThread< T, D > & operator=(const T *data)
Assign an object to the thread-local storage.
Definition: perThread.ipp:32
~PerThread()
Destruct the per-thread variable.
Definition: perThread.ipp:27
void set(const void *data)
Set the data for this thread-local storage.
Implements thread-specific storage for C++ objects.
Definition: perThread.h:57
T * operator->()
Access the thread-local object.
Definition: perThread.ipp:58
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:29
Provides thread-local storage API used by PerThread and PerThreadRef.
Definition: tls.h:31