Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:38:07

0001 //
0002 // detail/resolver_thread_pool.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_DETAIL_RESOLVER_THREAD_POOL_HPP
0012 #define BOOST_ASIO_DETAIL_RESOLVER_THREAD_POOL_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/execution_context.hpp>
0020 #include <boost/asio/detail/mutex.hpp>
0021 #include <boost/asio/detail/resolve_op.hpp>
0022 #include <boost/asio/detail/scheduler.hpp>
0023 #include <boost/asio/detail/thread_group.hpp>
0024 
0025 #if defined(BOOST_ASIO_HAS_IOCP)
0026 # include <boost/asio/detail/win_iocp_io_context.hpp>
0027 #else // defined(BOOST_ASIO_HAS_IOCP)
0028 # include <boost/asio/detail/scheduler.hpp>
0029 #endif // defined(BOOST_ASIO_HAS_IOCP)
0030 
0031 #include <boost/asio/detail/push_options.hpp>
0032 
0033 namespace boost {
0034 namespace asio {
0035 namespace detail {
0036 
0037 class resolver_thread_pool :
0038   public execution_context_service_base<resolver_thread_pool>
0039 {
0040 public:
0041 #if defined(BOOST_ASIO_HAS_IOCP)
0042   typedef class win_iocp_io_context scheduler_impl;
0043 #else
0044   typedef class scheduler scheduler_impl;
0045 #endif
0046 
0047   // Constructor.
0048   BOOST_ASIO_DECL resolver_thread_pool(execution_context& context);
0049 
0050   // Destructor.
0051   BOOST_ASIO_DECL ~resolver_thread_pool();
0052 
0053   // Destroy all user-defined handler objects owned by the service.
0054   BOOST_ASIO_DECL void shutdown();
0055 
0056   // Perform any fork-related housekeeping.
0057   BOOST_ASIO_DECL void notify_fork(execution_context::fork_event fork_ev);
0058 
0059   // Helper function to start an asynchronous resolve operation.
0060   BOOST_ASIO_DECL void start_resolve_op(resolve_op* op);
0061 
0062   // Get the underlying scheduler implementation.
0063   scheduler_impl& scheduler()
0064   {
0065     return scheduler_;
0066   }
0067 
0068 private:
0069   // Helper class to run the work scheduler in a thread.
0070   class work_scheduler_runner;
0071 
0072   // Start the work scheduler if it's not already running.
0073   BOOST_ASIO_DECL void start_work_threads();
0074 
0075   // The scheduler implementation used to post completions.
0076   scheduler_impl& scheduler_;
0077 
0078   // Mutex to protect access to internal data.
0079   boost::asio::detail::mutex mutex_;
0080 
0081   // Private scheduler used for performing asynchronous host resolution.
0082   scheduler_impl work_scheduler_;
0083 
0084   // Threads used for running the work scheduler's run loop.
0085   thread_group<execution_context::allocator<void>> work_threads_;
0086 
0087   // The number of threads used to run the work scheduler.
0088   unsigned int num_work_threads_;
0089 
0090   // Whether the scheduler locking is enabled.
0091   bool scheduler_locking_;
0092 
0093   // Whether the scheduler has been shut down.
0094   bool shutdown_;
0095 };
0096 
0097 } // namespace detail
0098 } // namespace asio
0099 } // namespace boost
0100 
0101 #include <boost/asio/detail/pop_options.hpp>
0102 
0103 #if defined(BOOST_ASIO_HEADER_ONLY)
0104 # include <boost/asio/detail/impl/resolver_thread_pool.ipp>
0105 #endif // defined(BOOST_ASIO_HEADER_ONLY)
0106 
0107 #endif // BOOST_ASIO_DETAIL_RESOLVER_THREAD_POOL_HPP