File indexing completed on 2025-01-18 09:28:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_IMPL_POSIX_THREAD_IPP
0012 #define BOOST_ASIO_DETAIL_IMPL_POSIX_THREAD_IPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019
0020 #if defined(BOOST_ASIO_HAS_PTHREADS)
0021
0022 #include <boost/asio/detail/posix_thread.hpp>
0023 #include <boost/asio/detail/throw_error.hpp>
0024 #include <boost/asio/error.hpp>
0025
0026 #include <boost/asio/detail/push_options.hpp>
0027
0028 namespace boost {
0029 namespace asio {
0030 namespace detail {
0031
0032 posix_thread::~posix_thread()
0033 {
0034 if (!joined_)
0035 ::pthread_detach(thread_);
0036 }
0037
0038 void posix_thread::join()
0039 {
0040 if (!joined_)
0041 {
0042 ::pthread_join(thread_, 0);
0043 joined_ = true;
0044 }
0045 }
0046
0047 std::size_t posix_thread::hardware_concurrency()
0048 {
0049 #if defined(_SC_NPROCESSORS_ONLN)
0050 long result = sysconf(_SC_NPROCESSORS_ONLN);
0051 if (result > 0)
0052 return result;
0053 #endif
0054 return 0;
0055 }
0056
0057 void posix_thread::start_thread(func_base* arg)
0058 {
0059 int error = ::pthread_create(&thread_, 0,
0060 boost_asio_detail_posix_thread_function, arg);
0061 if (error != 0)
0062 {
0063 delete arg;
0064 boost::system::error_code ec(error,
0065 boost::asio::error::get_system_category());
0066 boost::asio::detail::throw_error(ec, "thread");
0067 }
0068 }
0069
0070 void* boost_asio_detail_posix_thread_function(void* arg)
0071 {
0072 posix_thread::auto_func_base_ptr func = {
0073 static_cast<posix_thread::func_base*>(arg) };
0074 func.ptr->run();
0075 return 0;
0076 }
0077
0078 }
0079 }
0080 }
0081
0082 #include <boost/asio/detail/pop_options.hpp>
0083
0084 #endif
0085
0086 #endif