os/ossrv/ossrv_pub/boost_apis/boost/thread/tss.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/thread/tss.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,128 @@
     1.4 +// Copyright (C) 2001-2003 William E. Kempf
     1.5 +// Copyright (C) 2006 Roland Schwarz
     1.6 +//
     1.7 +//  Distributed under the Boost Software License, Version 1.0. (See accompanying 
     1.8 +//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     1.9 +
    1.10 +#ifndef BOOST_TSS_WEK070601_HPP
    1.11 +#define BOOST_TSS_WEK070601_HPP
    1.12 +
    1.13 +#include <boost/thread/detail/config.hpp>
    1.14 +
    1.15 +#include <boost/utility.hpp>
    1.16 +#include <boost/function.hpp>
    1.17 +#include <boost/thread/exceptions.hpp>
    1.18 +
    1.19 +#if defined(BOOST_HAS_PTHREADS)
    1.20 +#   include <pthread.h>
    1.21 +#elif defined(BOOST_HAS_MPTASKS)
    1.22 +#   include <Multiprocessing.h>
    1.23 +#endif
    1.24 +
    1.25 +namespace boost {
    1.26 +
    1.27 +// disable warnings about non dll import
    1.28 +// see: http://www.boost.org/more/separate_compilation.html#dlls
    1.29 +#ifdef BOOST_MSVC
    1.30 +#   pragma warning(push)
    1.31 +#   pragma warning(disable: 4251 4231 4660 4275)
    1.32 +#endif
    1.33 +
    1.34 +namespace detail {
    1.35 +
    1.36 +class BOOST_THREAD_DECL tss : private noncopyable
    1.37 +{
    1.38 +public:
    1.39 +    tss(boost::function1<void, void*>* pcleanup) {
    1.40 +        if (pcleanup == 0) throw boost::thread_resource_error();
    1.41 +        try
    1.42 +        {
    1.43 +            init(pcleanup);
    1.44 +        }
    1.45 +        catch (...)
    1.46 +        {
    1.47 +            delete pcleanup;
    1.48 +            throw boost::thread_resource_error();
    1.49 +        }
    1.50 +    }
    1.51 +
    1.52 +    ~tss();
    1.53 +    void* get() const;
    1.54 +    void set(void* value);
    1.55 +    void cleanup(void* p);
    1.56 +
    1.57 +private:
    1.58 +    unsigned int m_slot; //This is a "pseudo-slot", not a native slot
    1.59 +
    1.60 +    void init(boost::function1<void, void*>* pcleanup);
    1.61 +};
    1.62 +
    1.63 +#if defined(BOOST_HAS_MPTASKS)
    1.64 +void thread_cleanup();
    1.65 +#endif
    1.66 +
    1.67 +template <typename T>
    1.68 +struct tss_adapter
    1.69 +{
    1.70 +    template <typename F>
    1.71 +    tss_adapter(const F& cleanup) : m_cleanup(cleanup) { }
    1.72 +    void operator()(void* p) { m_cleanup(static_cast<T*>(p)); }
    1.73 +    boost::function1<void, T*> m_cleanup;
    1.74 +};
    1.75 +
    1.76 +} // namespace detail
    1.77 +
    1.78 +template <typename T>
    1.79 +class thread_specific_ptr : private noncopyable
    1.80 +{
    1.81 +public:
    1.82 +    thread_specific_ptr()
    1.83 +        : m_tss(new boost::function1<void, void*>(
    1.84 +                    boost::detail::tss_adapter<T>(
    1.85 +                        &thread_specific_ptr<T>::cleanup)))
    1.86 +    {
    1.87 +    }
    1.88 +    thread_specific_ptr(void (*clean)(T*))
    1.89 +        : m_tss(new boost::function1<void, void*>(
    1.90 +                    boost::detail::tss_adapter<T>(clean)))
    1.91 +    {
    1.92 +    }
    1.93 +    ~thread_specific_ptr() { reset(); }
    1.94 +
    1.95 +    T* get() const { return static_cast<T*>(m_tss.get()); }
    1.96 +    T* operator->() const { return get(); }
    1.97 +    T& operator*() const { return *get(); }
    1.98 +    T* release() { T* temp = get(); if (temp) m_tss.set(0); return temp; }
    1.99 +    void reset(T* p=0)
   1.100 +    {
   1.101 +        T* cur = get();
   1.102 +        if (cur == p) return;
   1.103 +        m_tss.set(p);
   1.104 +        if (cur) m_tss.cleanup(cur);
   1.105 +    }
   1.106 +
   1.107 +private:
   1.108 +    static void cleanup(T* p) { delete p; }
   1.109 +    detail::tss m_tss;
   1.110 +};
   1.111 +
   1.112 +#ifdef BOOST_MSVC
   1.113 +#   pragma warning(pop)
   1.114 +#endif
   1.115 +
   1.116 +} // namespace boost
   1.117 +
   1.118 +#endif //BOOST_TSS_WEK070601_HPP
   1.119 +
   1.120 +// Change Log:
   1.121 +//   6 Jun 01  
   1.122 +//      WEKEMPF Initial version.
   1.123 +//  30 May 02  WEKEMPF 
   1.124 +//      Added interface to set specific cleanup handlers.
   1.125 +//      Removed TLS slot limits from most implementations.
   1.126 +//  22 Mar 04 GlassfordM for WEKEMPF
   1.127 +//      Fixed: thread_specific_ptr::reset() doesn't check error returned
   1.128 +//          by tss::set(); tss::set() now throws if it fails.
   1.129 +//      Fixed: calling thread_specific_ptr::reset() or 
   1.130 +//          thread_specific_ptr::release() causes double-delete: once on
   1.131 +//          reset()/release() and once on ~thread_specific_ptr().