Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:47

0001 //
0002 // detail/win_tss_ptr.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP
0012 #define BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 
0020 #if defined(BOOST_ASIO_WINDOWS)
0021 
0022 #include <boost/asio/detail/noncopyable.hpp>
0023 #include <boost/asio/detail/socket_types.hpp>
0024 
0025 #include <boost/asio/detail/push_options.hpp>
0026 
0027 namespace boost {
0028 namespace asio {
0029 namespace detail {
0030 
0031 // Helper function to create thread-specific storage.
0032 BOOST_ASIO_DECL DWORD win_tss_ptr_create();
0033 
0034 template <typename T>
0035 class win_tss_ptr
0036   : private noncopyable
0037 {
0038 public:
0039   // Constructor.
0040   win_tss_ptr()
0041     : tss_key_(win_tss_ptr_create())
0042   {
0043   }
0044 
0045   // Destructor.
0046   ~win_tss_ptr()
0047   {
0048     ::TlsFree(tss_key_);
0049   }
0050 
0051   // Get the value.
0052   operator T*() const
0053   {
0054     return static_cast<T*>(::TlsGetValue(tss_key_));
0055   }
0056 
0057   // Set the value.
0058   void operator=(T* value)
0059   {
0060     ::TlsSetValue(tss_key_, value);
0061   }
0062 
0063 private:
0064   // Thread-specific storage to allow unlocked access to determine whether a
0065   // thread is a member of the pool.
0066   DWORD tss_key_;
0067 };
0068 
0069 } // namespace detail
0070 } // namespace asio
0071 } // namespace boost
0072 
0073 #include <boost/asio/detail/pop_options.hpp>
0074 
0075 #if defined(BOOST_ASIO_HEADER_ONLY)
0076 # include <boost/asio/detail/impl/win_tss_ptr.ipp>
0077 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0078 
0079 #endif // defined(BOOST_ASIO_WINDOWS)
0080 
0081 #endif // BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP