00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_DETAIL_WIN_TSS_PTR_HPP
00012 #define ASIO_DETAIL_WIN_TSS_PTR_HPP
00013
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017
00018 #include "asio/detail/push_options.hpp"
00019
00020 #include "asio/detail/push_options.hpp"
00021 #include <boost/config.hpp>
00022 #include "asio/detail/pop_options.hpp"
00023
00024 #if defined(BOOST_WINDOWS)
00025
00026 #include "asio/system_error.hpp"
00027 #include "asio/detail/noncopyable.hpp"
00028 #include "asio/detail/socket_types.hpp"
00029
00030 #include "asio/detail/push_options.hpp"
00031 #include <boost/throw_exception.hpp>
00032 #include "asio/detail/pop_options.hpp"
00033
00034 namespace asio {
00035 namespace detail {
00036
00037 template <typename T>
00038 class win_tss_ptr
00039 : private noncopyable
00040 {
00041 public:
00042
00043 win_tss_ptr()
00044 {
00045 tss_key_ = ::TlsAlloc();
00046 if (tss_key_ == TLS_OUT_OF_INDEXES)
00047 {
00048 DWORD last_error = ::GetLastError();
00049 asio::system_error e(
00050 asio::error_code(last_error, asio::native_ecat),
00051 "tss");
00052 boost::throw_exception(e);
00053 }
00054 }
00055
00056
00057 ~win_tss_ptr()
00058 {
00059 ::TlsFree(tss_key_);
00060 }
00061
00062
00063 operator T*() const
00064 {
00065 return static_cast<T*>(::TlsGetValue(tss_key_));
00066 }
00067
00068
00069 void operator=(T* value)
00070 {
00071 ::TlsSetValue(tss_key_, value);
00072 }
00073
00074 private:
00075
00076
00077 DWORD tss_key_;
00078 };
00079
00080 }
00081 }
00082
00083 #endif // defined(BOOST_WINDOWS)
00084
00085 #include "asio/detail/pop_options.hpp"
00086
00087 #endif // ASIO_DETAIL_WIN_TSS_PTR_HPP