00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_DETAIL_POSIX_TSS_PTR_HPP
00012 #define ASIO_DETAIL_POSIX_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_HAS_PTHREADS)
00025
00026 #include "asio/detail/push_options.hpp"
00027 #include <boost/throw_exception.hpp>
00028 #include <pthread.h>
00029 #include "asio/detail/pop_options.hpp"
00030
00031 #include "asio/system_error.hpp"
00032 #include "asio/detail/noncopyable.hpp"
00033
00034 namespace asio {
00035 namespace detail {
00036
00037 template <typename T>
00038 class posix_tss_ptr
00039 : private noncopyable
00040 {
00041 public:
00042
00043 posix_tss_ptr()
00044 {
00045 int error = ::pthread_key_create(&tss_key_, 0);
00046 if (error != 0)
00047 {
00048 asio::system_error e(
00049 asio::error_code(error, asio::native_ecat),
00050 "tss");
00051 boost::throw_exception(e);
00052 }
00053 }
00054
00055
00056 ~posix_tss_ptr()
00057 {
00058 ::pthread_key_delete(tss_key_);
00059 }
00060
00061
00062 operator T*() const
00063 {
00064 return static_cast<T*>(::pthread_getspecific(tss_key_));
00065 }
00066
00067
00068 void operator=(T* value)
00069 {
00070 ::pthread_setspecific(tss_key_, value);
00071 }
00072
00073 private:
00074
00075
00076 pthread_key_t tss_key_;
00077 };
00078
00079 }
00080 }
00081
00082 #endif // defined(BOOST_HAS_PTHREADS)
00083
00084 #include "asio/detail/pop_options.hpp"
00085
00086 #endif // ASIO_DETAIL_POSIX_TSS_PTR_HPP