fix doc example typo
[boost.git] / boost / asio / detail / win_tss_ptr.hpp
blob5c56454f8712a4aab03dde27504bd78743fbc5ac
1 //
2 // win_tss_ptr.hpp
3 // ~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
11 #ifndef BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP
12 #define BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/push_options.hpp>
20 #include <boost/asio/detail/push_options.hpp>
21 #include <boost/config.hpp>
22 #include <boost/system/system_error.hpp>
23 #include <boost/asio/detail/pop_options.hpp>
25 #if defined(BOOST_WINDOWS)
27 #include <boost/asio/error.hpp>
28 #include <boost/asio/detail/noncopyable.hpp>
29 #include <boost/asio/detail/socket_types.hpp>
31 #include <boost/asio/detail/push_options.hpp>
32 #include <boost/throw_exception.hpp>
33 #include <boost/asio/detail/pop_options.hpp>
35 namespace boost {
36 namespace asio {
37 namespace detail {
39 template <typename T>
40 class win_tss_ptr
41 : private noncopyable
43 public:
44 #if defined(UNDER_CE)
45 enum { out_of_indexes = 0xFFFFFFFF };
46 #else
47 enum { out_of_indexes = TLS_OUT_OF_INDEXES };
48 #endif
50 // Constructor.
51 win_tss_ptr()
53 tss_key_ = ::TlsAlloc();
54 if (tss_key_ == out_of_indexes)
56 DWORD last_error = ::GetLastError();
57 boost::system::system_error e(
58 boost::system::error_code(last_error,
59 boost::asio::error::get_system_category()),
60 "tss");
61 boost::throw_exception(e);
65 // Destructor.
66 ~win_tss_ptr()
68 ::TlsFree(tss_key_);
71 // Get the value.
72 operator T*() const
74 return static_cast<T*>(::TlsGetValue(tss_key_));
77 // Set the value.
78 void operator=(T* value)
80 ::TlsSetValue(tss_key_, value);
83 private:
84 // Thread-specific storage to allow unlocked access to determine whether a
85 // thread is a member of the pool.
86 DWORD tss_key_;
89 } // namespace detail
90 } // namespace asio
91 } // namespace boost
93 #endif // defined(BOOST_WINDOWS)
95 #include <boost/asio/detail/pop_options.hpp>
97 #endif // BOOST_ASIO_DETAIL_WIN_TSS_PTR_HPP