Go to the documentation of this file.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/error.hpp"
00032 #include "asio/system_error.hpp"
00033 #include "asio/detail/noncopyable.hpp"
00034
00035 namespace asio {
00036 namespace detail {
00037
00038 template <typename T>
00039 class posix_tss_ptr
00040 : private noncopyable
00041 {
00042 public:
00043
00044 posix_tss_ptr()
00045 {
00046 int error = ::pthread_key_create(&tss_key_, 0);
00047 if (error != 0)
00048 {
00049 asio::system_error e(
00050 asio::error_code(error,
00051 asio::error::get_system_category()),
00052 "tss");
00053 boost::throw_exception(e);
00054 }
00055 }
00056
00057
00058 ~posix_tss_ptr()
00059 {
00060 ::pthread_key_delete(tss_key_);
00061 }
00062
00063
00064 operator T*() const
00065 {
00066 return static_cast<T*>(::pthread_getspecific(tss_key_));
00067 }
00068
00069
00070 void operator=(T* value)
00071 {
00072 ::pthread_setspecific(tss_key_, value);
00073 }
00074
00075 private:
00076
00077
00078 pthread_key_t tss_key_;
00079 };
00080
00081 }
00082 }
00083
00084 #endif // defined(BOOST_HAS_PTHREADS)
00085
00086 #include "asio/detail/pop_options.hpp"
00087
00088 #endif // ASIO_DETAIL_POSIX_TSS_PTR_HPP