123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #ifndef BOOST_ASIO_DETAIL_POSIX_TSS_PTR_HPP
- #define BOOST_ASIO_DETAIL_POSIX_TSS_PTR_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/asio/detail/push_options.hpp>
- #include <boost/asio/detail/push_options.hpp>
- #include <boost/config.hpp>
- #include <boost/system/system_error.hpp>
- #include <boost/asio/detail/pop_options.hpp>
- #if defined(BOOST_HAS_PTHREADS)
- #include <boost/asio/detail/push_options.hpp>
- #include <boost/throw_exception.hpp>
- #include <pthread.h>
- #include <boost/asio/detail/pop_options.hpp>
- #include <boost/asio/error.hpp>
- #include <boost/asio/detail/noncopyable.hpp>
- namespace boost {
- namespace asio {
- namespace detail {
- template <typename T>
- class posix_tss_ptr
- : private noncopyable
- {
- public:
-
- posix_tss_ptr()
- {
- int error = ::pthread_key_create(&tss_key_, 0);
- if (error != 0)
- {
- boost::system::system_error e(
- boost::system::error_code(error,
- boost::asio::error::get_system_category()),
- "tss");
- boost::throw_exception(e);
- }
- }
-
- ~posix_tss_ptr()
- {
- ::pthread_key_delete(tss_key_);
- }
-
- operator T*() const
- {
- return static_cast<T*>(::pthread_getspecific(tss_key_));
- }
-
- void operator=(T* value)
- {
- ::pthread_setspecific(tss_key_, value);
- }
- private:
-
-
- pthread_key_t tss_key_;
- };
- }
- }
- }
- #endif
- #include <boost/asio/detail/pop_options.hpp>
- #endif
|