File indexing completed on 2025-01-18 09:28:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_POSIX_THREAD_HPP
0012 #define BOOST_ASIO_DETAIL_POSIX_THREAD_HPP
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 <cstddef>
0023 #include <pthread.h>
0024 #include <boost/asio/detail/noncopyable.hpp>
0025
0026 #include <boost/asio/detail/push_options.hpp>
0027
0028 namespace boost {
0029 namespace asio {
0030 namespace detail {
0031
0032 extern "C"
0033 {
0034 BOOST_ASIO_DECL void* boost_asio_detail_posix_thread_function(void* arg);
0035 }
0036
0037 class posix_thread
0038 : private noncopyable
0039 {
0040 public:
0041
0042 template <typename Function>
0043 posix_thread(Function f, unsigned int = 0)
0044 : joined_(false)
0045 {
0046 start_thread(new func<Function>(f));
0047 }
0048
0049
0050 BOOST_ASIO_DECL ~posix_thread();
0051
0052
0053 BOOST_ASIO_DECL void join();
0054
0055
0056 BOOST_ASIO_DECL static std::size_t hardware_concurrency();
0057
0058 private:
0059 friend void* boost_asio_detail_posix_thread_function(void* arg);
0060
0061 class func_base
0062 {
0063 public:
0064 virtual ~func_base() {}
0065 virtual void run() = 0;
0066 };
0067
0068 struct auto_func_base_ptr
0069 {
0070 func_base* ptr;
0071 ~auto_func_base_ptr() { delete ptr; }
0072 };
0073
0074 template <typename Function>
0075 class func
0076 : public func_base
0077 {
0078 public:
0079 func(Function f)
0080 : f_(f)
0081 {
0082 }
0083
0084 virtual void run()
0085 {
0086 f_();
0087 }
0088
0089 private:
0090 Function f_;
0091 };
0092
0093 BOOST_ASIO_DECL void start_thread(func_base* arg);
0094
0095 ::pthread_t thread_;
0096 bool joined_;
0097 };
0098
0099 }
0100 }
0101 }
0102
0103 #include <boost/asio/detail/pop_options.hpp>
0104
0105 #if defined(BOOST_ASIO_HEADER_ONLY)
0106 # include <boost/asio/detail/impl/posix_thread.ipp>
0107 #endif
0108
0109 #endif
0110
0111 #endif