diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/posix_thread.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/posix_thread.hpp | 78 |
1 files changed, 27 insertions, 51 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/posix_thread.hpp b/3rdParty/Boost/src/boost/asio/detail/posix_thread.hpp index 41d8bc9..a87e396 100644 --- a/3rdParty/Boost/src/boost/asio/detail/posix_thread.hpp +++ b/3rdParty/Boost/src/boost/asio/detail/posix_thread.hpp @@ -1,6 +1,6 @@ // -// posix_thread.hpp -// ~~~~~~~~~~~~~~~~ +// detail/posix_thread.hpp +// ~~~~~~~~~~~~~~~~~~~~~~~ // // Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com) // @@ -15,29 +15,23 @@ # pragma once #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) -#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> +#include <boost/asio/detail/config.hpp> -#if defined(BOOST_HAS_PTHREADS) +#if defined(BOOST_HAS_PTHREADS) && !defined(BOOST_ASIO_DISABLE_THREADS) -#include <boost/asio/detail/push_options.hpp> -#include <memory> -#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> +#include <boost/asio/detail/push_options.hpp> + namespace boost { namespace asio { namespace detail { -extern "C" void* boost_asio_detail_posix_thread_function(void* arg); +extern "C" +{ + BOOST_ASIO_DECL void* boost_asio_detail_posix_thread_function(void* arg); +} class posix_thread : private noncopyable @@ -48,36 +42,14 @@ public: posix_thread(Function f) : joined_(false) { - std::auto_ptr<func_base> arg(new func<Function>(f)); - int error = ::pthread_create(&thread_, 0, - boost_asio_detail_posix_thread_function, arg.get()); - if (error != 0) - { - boost::system::system_error e( - boost::system::error_code(error, - boost::asio::error::get_system_category()), - "thread"); - boost::throw_exception(e); - } - arg.release(); + start_thread(new func<Function>(f)); } // Destructor. - ~posix_thread() - { - if (!joined_) - ::pthread_detach(thread_); - } + BOOST_ASIO_DECL ~posix_thread(); // Wait for the thread to exit. - void join() - { - if (!joined_) - { - ::pthread_join(thread_, 0); - joined_ = true; - } - } + BOOST_ASIO_DECL void join(); private: friend void* boost_asio_detail_posix_thread_function(void* arg); @@ -89,6 +61,12 @@ private: virtual void run() = 0; }; + struct auto_func_base_ptr + { + func_base* ptr; + ~auto_func_base_ptr() { delete ptr; } + }; + template <typename Function> class func : public func_base @@ -108,24 +86,22 @@ private: Function f_; }; + BOOST_ASIO_DECL void start_thread(func_base* arg); + ::pthread_t thread_; bool joined_; }; -inline void* boost_asio_detail_posix_thread_function(void* arg) -{ - std::auto_ptr<posix_thread::func_base> f( - static_cast<posix_thread::func_base*>(arg)); - f->run(); - return 0; -} - } // namespace detail } // namespace asio } // namespace boost -#endif // defined(BOOST_HAS_PTHREADS) - #include <boost/asio/detail/pop_options.hpp> +#if defined(BOOST_ASIO_HEADER_ONLY) +# include <boost/asio/detail/impl/posix_thread.ipp> +#endif // defined(BOOST_ASIO_HEADER_ONLY) + +#endif // defined(BOOST_HAS_PTHREADS) && !defined(BOOST_ASIO_DISABLE_THREADS) + #endif // BOOST_ASIO_DETAIL_POSIX_THREAD_HPP |