template<class T>
class ThreadLocalPointer< T >
Copyright (C) 2011 University of Rochester Department of Computer Science and Lehigh University Department of Computer Science and Engineering
License: Modified BSD Please see the file LICENSE.RSTM for licensing information To use a ThreadLocalPointer, declare one in a header like this: extern ThreadLocalPointer<foo> my_foo;
Then you must back the pointer in a cpp file like this: ThreadLocalPointer<foo> currentHeap; if defined(LOCAL_POINTER_ANNOTATION) template <> LOCAL_POINTER_ANNOTATION foo* ThreadLocalPointer<foo>::thr_local_key = NULL; #endif This if block serves three roles:
- It includes files as necessary for different pthread implementations
- It hides differences between VisualC++ and GCC syntax
- It makes sure that a valid thread-local option is specified so that subsequent #ifs don't have to do error checking Hide the fact that some of our platforms use pthread_getspecific while others use os-specific thread local storage mechanisms. In all cases, if you instantiate one of these with a T, then you'll get a thread-local pointer to a T that is easy to access and platform independent