]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/thread/tss.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / thread / tss.hpp
index d798bef558ac72376dd579bd22ab053faa744bc4..bcfbdf0f9f7784a3d03fe72ffd3afb9ef936f25b 100644 (file)
@@ -6,8 +6,8 @@
 // (C) Copyright 2007-8 Anthony Williams
 
 #include <boost/thread/detail/config.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/thread/detail/thread_heap_alloc.hpp>
+
+#include <boost/type_traits/add_reference.hpp>
 
 #include <boost/config/abi_prefix.hpp>
 
@@ -15,15 +15,13 @@ namespace boost
 {
     namespace detail
     {
-        struct tss_cleanup_function
+        namespace thread
         {
-            virtual ~tss_cleanup_function()
-            {}
-
-            virtual void operator()(void* data)=0;
-        };
+            typedef void(*cleanup_func_t)(void*);
+            typedef void(*cleanup_caller_t)(cleanup_func_t, void*);
+        }
 
-        BOOST_THREAD_DECL void set_tss_data(void const* key,boost::shared_ptr<tss_cleanup_function> func,void* tss_data,bool cleanup_existing);
+        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);
         BOOST_THREAD_DECL void* get_tss_data(void const* key);
     }
 
@@ -34,49 +32,33 @@ namespace boost
         thread_specific_ptr(thread_specific_ptr&);
         thread_specific_ptr& operator=(thread_specific_ptr&);
 
-        struct delete_data:
-            detail::tss_cleanup_function
-        {
-            void operator()(void* data)
-            {
-                delete static_cast<T*>(data);
-            }
-        };
+        typedef void(*original_cleanup_func_t)(T*);
 
-        struct run_custom_cleanup_function:
-            detail::tss_cleanup_function
+        static void default_deleter(T* data)
         {
-            void (*cleanup_function)(T*);
-
-            explicit run_custom_cleanup_function(void (*cleanup_function_)(T*)):
-                cleanup_function(cleanup_function_)
-            {}
+            delete data;
+        }
 
-            void operator()(void* data)
-            {
-                cleanup_function(static_cast<T*>(data));
-            }
-        };
+        static void cleanup_caller(detail::thread::cleanup_func_t cleanup_function,void* data)
+        {
+            reinterpret_cast<original_cleanup_func_t>(cleanup_function)(static_cast<T*>(data));
+        }
 
 
-        boost::shared_ptr<detail::tss_cleanup_function> cleanup;
+        detail::thread::cleanup_func_t cleanup;
 
     public:
         typedef T element_type;
 
         thread_specific_ptr():
-            cleanup(detail::heap_new<delete_data>(),detail::do_heap_delete<delete_data>())
+            cleanup(reinterpret_cast<detail::thread::cleanup_func_t>(&default_deleter))
         {}
         explicit thread_specific_ptr(void (*func_)(T*))
-        {
-            if(func_)
-            {
-                cleanup.reset(detail::heap_new<run_custom_cleanup_function>(func_),detail::do_heap_delete<run_custom_cleanup_function>());
-            }
-        }
+          : cleanup(reinterpret_cast<detail::thread::cleanup_func_t>(func_))
+        {}
         ~thread_specific_ptr()
         {
-            detail::set_tss_data(this,boost::shared_ptr<detail::tss_cleanup_function>(),0,true);
+            detail::set_tss_data(this,0,0,0,true);
         }
 
         T* get() const
@@ -87,14 +69,14 @@ namespace boost
         {
             return get();
         }
-        typename boost::detail::sp_dereference< T >::type operator*() const
+        typename add_reference<T>::type operator*() const
         {
             return *get();
         }
         T* release()
         {
             T* const temp=get();
-            detail::set_tss_data(this,boost::shared_ptr<detail::tss_cleanup_function>(),0,false);
+            detail::set_tss_data(this,0,0,0,false);
             return temp;
         }
         void reset(T* new_value=0)
@@ -102,7 +84,7 @@ namespace boost
             T* const current_value=get();
             if(current_value!=new_value)
             {
-                detail::set_tss_data(this,cleanup,new_value,true);
+                detail::set_tss_data(this,&cleanup_caller,cleanup,new_value,true);
             }
         }
     };