Lunchbox  1.14.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* ) > PerThread<T, D>::PerThread()
21  : tls_( (TLS::ThreadDestructor_t)D )
22 {}
23 
24 template< class T, void (*D)( T* ) > PerThread<T, D>::~PerThread()
25 {}
26 
27 template< class T, void (*D)( T* ) >
29 {
30  tls_.set( static_cast< const void* >( data ));
31  return *this;
32 }
33 
34 template< class T, void (*D)( T* ) >
36 {
37  tls_.set( rhs.tls_.get( ));
38  return *this;
39 }
40 
41 template< class T, void (*D)( T* ) > T* PerThread<T, D>::get()
42 {
43  return static_cast< T* >( tls_.get( ));
44 }
45 
46 template< class T, void (*D)( T* ) > const T* PerThread<T, D>::get() const
47 {
48  return static_cast< const T* >( tls_.get( ));
49 }
50 
51 template< class T, void (*D)( T* ) > T* PerThread<T, D>::operator->()
52 {
53  return static_cast< T* >( tls_.get( ));
54 }
55 
56 template< class T, void (*D)( T* ) >
58 {
59  return static_cast< T* >( tls_.get( ));
60 }
61 
62 template< class T, void (*D)( T* ) > bool PerThread<T, D>::operator ! () const
63 {
64  return tls_.get() == 0;
65 }
66 
67 template< class T, void (*D)( T* ) > bool PerThread<T, D>::isValid() const
68 {
69  return tls_.get() != 0;
70 }
71 }
PerThread()
Construct a new per-thread variable.
Definition: perThread.ipp:20
void * get()
bool isValid() const
Definition: perThread.ipp:67
bool operator!() const
Definition: perThread.ipp:62
PerThread< T, D > & operator=(const T *data)
Assign an object to the thread-local storage.
Definition: perThread.ipp:28
~PerThread()
Destruct the per-thread variable.
Definition: perThread.ipp:24
void set(const void *data)
Set the data for this thread-local storage.
Implements thread-specific storage for C++ objects.
Definition: perThread.h:47
T * operator->()
Access the thread-local object.
Definition: perThread.ipp:51
Abstraction layer and common utilities for multi-threaded programming.
Definition: algorithm.h:32
Provides thread-local storage API used by PerThread and PerThreadRef.
Definition: tls.h:28