1 #ifndef BOOST_THREAD_TSS_HPP
2 #define BOOST_THREAD_TSS_HPP
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 // (C) Copyright 2007-8 Anthony Williams
8 #include <boost/thread/detail/config.hpp>
10 #include <boost/type_traits/add_reference.hpp>
12 #include <boost/config/abi_prefix.hpp>
20 typedef void(*cleanup_func_t)(void*);
21 typedef void(*cleanup_caller_t)(cleanup_func_t, void*);
24 BOOST_THREAD_DECL void set_tss_data(void const* key,detail::thread::cleanup_caller_t caller,detail::thread::cleanup_func_t func,void* tss_data,bool cleanup_existing);
25 BOOST_THREAD_DECL void* get_tss_data(void const* key);
29 class thread_specific_ptr
32 thread_specific_ptr(thread_specific_ptr&);
33 thread_specific_ptr& operator=(thread_specific_ptr&);
35 typedef void(*original_cleanup_func_t)(T*);
37 static void default_deleter(T* data)
42 static void cleanup_caller(detail::thread::cleanup_func_t cleanup_function,void* data)
44 reinterpret_cast<original_cleanup_func_t>(cleanup_function)(static_cast<T*>(data));
48 detail::thread::cleanup_func_t cleanup;
51 typedef T element_type;
53 thread_specific_ptr():
54 cleanup(reinterpret_cast<detail::thread::cleanup_func_t>(&default_deleter))
56 explicit thread_specific_ptr(void (*func_)(T*))
57 : cleanup(reinterpret_cast<detail::thread::cleanup_func_t>(func_))
59 ~thread_specific_ptr()
61 detail::set_tss_data(this,0,0,0,true);
66 return static_cast<T*>(detail::get_tss_data(this));
72 typename add_reference<T>::type operator*() const
79 detail::set_tss_data(this,0,0,0,false);
82 void reset(T* new_value=0)
84 T* const current_value=get();
85 if(current_value!=new_value)
87 detail::set_tss_data(this,&cleanup_caller,cleanup,new_value,true);
93 #include <boost/config/abi_suffix.hpp>