2 // detail/impl/posix_thread.ipp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_DETAIL_IMPL_POSIX_THREAD_IPP
12 #define BOOST_ASIO_DETAIL_IMPL_POSIX_THREAD_IPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_HAS_PTHREADS)
22 #include <boost/asio/detail/posix_thread.hpp>
23 #include <boost/asio/detail/throw_error.hpp>
24 #include <boost/asio/error.hpp>
26 #include <boost/asio/detail/push_options.hpp>
32 posix_thread::~posix_thread()
35 ::pthread_detach(thread_);
38 void posix_thread::join()
42 ::pthread_join(thread_, 0);
47 std::size_t posix_thread::hardware_concurrency()
49 #if defined(_SC_NPROCESSORS_ONLN)
50 long result = sysconf(_SC_NPROCESSORS_ONLN);
53 #endif // defined(_SC_NPROCESSORS_ONLN)
57 void posix_thread::start_thread(func_base* arg)
59 int error = ::pthread_create(&thread_, 0,
60 boost_asio_detail_posix_thread_function, arg);
64 boost::system::error_code ec(error,
65 boost::asio::error::get_system_category());
66 boost::asio::detail::throw_error(ec, "thread");
70 void* boost_asio_detail_posix_thread_function(void* arg)
72 posix_thread::auto_func_base_ptr func = {
73 static_cast<posix_thread::func_base*>(arg) };
82 #include <boost/asio/detail/pop_options.hpp>
84 #endif // defined(BOOST_ASIO_HAS_PTHREADS)
86 #endif // BOOST_ASIO_DETAIL_IMPL_POSIX_THREAD_IPP