Chris@16: // Chris@16: // detail/win_tss_ptr.hpp Chris@16: // ~~~~~~~~~~~~~~~~~~~~~~ Chris@16: // Chris@101: // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: Chris@16: #ifndef BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP Chris@16: #define BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP Chris@16: Chris@16: #if defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: # pragma once Chris@16: #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_WINDOWS) Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace asio { Chris@16: namespace detail { Chris@16: Chris@16: // Helper function to create thread-specific storage. Chris@16: BOOST_ASIO_DECL DWORD win_tss_ptr_create(); Chris@16: Chris@16: template Chris@16: class win_tss_ptr Chris@16: : private noncopyable Chris@16: { Chris@16: public: Chris@16: // Constructor. Chris@16: win_tss_ptr() Chris@16: : tss_key_(win_tss_ptr_create()) Chris@16: { Chris@16: } Chris@16: Chris@16: // Destructor. Chris@16: ~win_tss_ptr() Chris@16: { Chris@16: ::TlsFree(tss_key_); Chris@16: } Chris@16: Chris@16: // Get the value. Chris@16: operator T*() const Chris@16: { Chris@16: return static_cast(::TlsGetValue(tss_key_)); Chris@16: } Chris@16: Chris@16: // Set the value. Chris@16: void operator=(T* value) Chris@16: { Chris@16: ::TlsSetValue(tss_key_, value); Chris@16: } Chris@16: Chris@16: private: Chris@16: // Thread-specific storage to allow unlocked access to determine whether a Chris@16: // thread is a member of the pool. Chris@16: DWORD tss_key_; Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace asio Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_ASIO_HEADER_ONLY) Chris@16: # include Chris@16: #endif // defined(BOOST_ASIO_HEADER_ONLY) Chris@16: Chris@16: #endif // defined(BOOST_ASIO_WINDOWS) Chris@16: Chris@16: #endif // BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP