io_context.hpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  1. //
  2. // io_context.hpp
  3. // ~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2025 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  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)
  9. //
  10. #ifndef BOOST_ASIO_IO_CONTEXT_HPP
  11. #define BOOST_ASIO_IO_CONTEXT_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <cstddef>
  17. #include <stdexcept>
  18. #include <typeinfo>
  19. #include <boost/asio/async_result.hpp>
  20. #include <boost/asio/detail/chrono.hpp>
  21. #include <boost/asio/detail/concurrency_hint.hpp>
  22. #include <boost/asio/detail/cstdint.hpp>
  23. #include <boost/asio/detail/wrapped_handler.hpp>
  24. #include <boost/system/error_code.hpp>
  25. #include <boost/asio/execution.hpp>
  26. #include <boost/asio/execution_context.hpp>
  27. #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
  28. # include <boost/asio/detail/winsock_init.hpp>
  29. #elif defined(__sun) || defined(__QNX__) || defined(__hpux) || defined(_AIX) \
  30. || defined(__osf__)
  31. # include <boost/asio/detail/signal_init.hpp>
  32. #endif
  33. #if defined(BOOST_ASIO_HAS_IOCP)
  34. # include <boost/asio/detail/win_iocp_io_context.hpp>
  35. #else
  36. # include <boost/asio/detail/scheduler.hpp>
  37. #endif
  38. #include <boost/asio/detail/push_options.hpp>
  39. namespace boost {
  40. namespace asio {
  41. namespace detail {
  42. #if defined(BOOST_ASIO_HAS_IOCP)
  43. typedef win_iocp_io_context io_context_impl;
  44. class win_iocp_overlapped_ptr;
  45. #else
  46. typedef scheduler io_context_impl;
  47. #endif
  48. struct io_context_bits
  49. {
  50. static constexpr uintptr_t blocking_never = 1;
  51. static constexpr uintptr_t relationship_continuation = 2;
  52. static constexpr uintptr_t outstanding_work_tracked = 4;
  53. static constexpr uintptr_t runtime_bits = 3;
  54. };
  55. } // namespace detail
  56. /// Provides core I/O functionality.
  57. /**
  58. * The io_context class provides the core I/O functionality for users of the
  59. * asynchronous I/O objects, including:
  60. *
  61. * @li boost::asio::ip::tcp::socket
  62. * @li boost::asio::ip::tcp::acceptor
  63. * @li boost::asio::ip::udp::socket
  64. * @li boost::asio::deadline_timer.
  65. *
  66. * The io_context class also includes facilities intended for developers of
  67. * custom asynchronous services.
  68. *
  69. * @par Thread Safety
  70. * @e Distinct @e objects: Safe.@n
  71. * @e Shared @e objects: Safe, with the specific exceptions of the restart()
  72. * and notify_fork() functions. Calling restart() while there are unfinished
  73. * run(), run_one(), run_for(), run_until(), poll() or poll_one() calls results
  74. * in undefined behaviour. The notify_fork() function should not be called
  75. * while any io_context function, or any function on an I/O object that is
  76. * associated with the io_context, is being called in another thread.
  77. *
  78. * @par Concepts:
  79. * Dispatcher.
  80. *
  81. * @par Synchronous and asynchronous operations
  82. *
  83. * Synchronous operations on I/O objects implicitly run the io_context object
  84. * for an individual operation. The io_context functions run(), run_one(),
  85. * run_for(), run_until(), poll() or poll_one() must be called for the
  86. * io_context to perform asynchronous operations on behalf of a C++ program.
  87. * Notification that an asynchronous operation has completed is delivered by
  88. * invocation of the associated handler. Handlers are invoked only by a thread
  89. * that is currently calling any overload of run(), run_one(), run_for(),
  90. * run_until(), poll() or poll_one() for the io_context.
  91. *
  92. * @par Effect of exceptions thrown from handlers
  93. *
  94. * If an exception is thrown from a handler, the exception is allowed to
  95. * propagate through the throwing thread's invocation of run(), run_one(),
  96. * run_for(), run_until(), poll() or poll_one(). No other threads that are
  97. * calling any of these functions are affected. It is then the responsibility
  98. * of the application to catch the exception.
  99. *
  100. * After the exception has been caught, the run(), run_one(), run_for(),
  101. * run_until(), poll() or poll_one() call may be restarted @em without the need
  102. * for an intervening call to restart(). This allows the thread to rejoin the
  103. * io_context object's thread pool without impacting any other threads in the
  104. * pool.
  105. *
  106. * For example:
  107. *
  108. * @code
  109. * boost::asio::io_context io_context;
  110. * ...
  111. * for (;;)
  112. * {
  113. * try
  114. * {
  115. * io_context.run();
  116. * break; // run() exited normally
  117. * }
  118. * catch (my_exception& e)
  119. * {
  120. * // Deal with exception as appropriate.
  121. * }
  122. * }
  123. * @endcode
  124. *
  125. * @par Submitting arbitrary tasks to the io_context
  126. *
  127. * To submit functions to the io_context, use the @ref boost::asio::dispatch,
  128. * @ref boost::asio::post or @ref boost::asio::defer free functions.
  129. *
  130. * For example:
  131. *
  132. * @code void my_task()
  133. * {
  134. * ...
  135. * }
  136. *
  137. * ...
  138. *
  139. * boost::asio::io_context io_context;
  140. *
  141. * // Submit a function to the io_context.
  142. * boost::asio::post(io_context, my_task);
  143. *
  144. * // Submit a lambda object to the io_context.
  145. * boost::asio::post(io_context,
  146. * []()
  147. * {
  148. * ...
  149. * });
  150. *
  151. * // Run the io_context until it runs out of work.
  152. * io_context.run(); @endcode
  153. *
  154. * @par Stopping the io_context from running out of work
  155. *
  156. * Some applications may need to prevent an io_context object's run() call from
  157. * returning when there is no more work to do. For example, the io_context may
  158. * be being run in a background thread that is launched prior to the
  159. * application's asynchronous operations. The run() call may be kept running by
  160. * using the @ref make_work_guard function to create an object of type
  161. * boost::asio::executor_work_guard<io_context::executor_type>:
  162. *
  163. * @code boost::asio::io_context io_context;
  164. * boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
  165. * = boost::asio::make_work_guard(io_context);
  166. * ... @endcode
  167. *
  168. * To effect a shutdown, the application will then need to call the io_context
  169. * object's stop() member function. This will cause the io_context run() call
  170. * to return as soon as possible, abandoning unfinished operations and without
  171. * permitting ready handlers to be dispatched.
  172. *
  173. * Alternatively, if the application requires that all operations and handlers
  174. * be allowed to finish normally, the work object may be explicitly reset.
  175. *
  176. * @code boost::asio::io_context io_context;
  177. * boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
  178. * = boost::asio::make_work_guard(io_context);
  179. * ...
  180. * work.reset(); // Allow run() to exit. @endcode
  181. */
  182. class io_context
  183. : public execution_context
  184. {
  185. private:
  186. typedef detail::io_context_impl impl_type;
  187. #if defined(BOOST_ASIO_HAS_IOCP)
  188. friend class detail::win_iocp_overlapped_ptr;
  189. #endif
  190. public:
  191. template <typename Allocator, uintptr_t Bits>
  192. class basic_executor_type;
  193. template <typename Allocator, uintptr_t Bits>
  194. friend class basic_executor_type;
  195. /// Executor used to submit functions to an io_context.
  196. typedef basic_executor_type<std::allocator<void>, 0> executor_type;
  197. class service;
  198. #if !defined(BOOST_ASIO_NO_EXTENSIONS) \
  199. && !defined(BOOST_ASIO_NO_TS_EXECUTORS)
  200. class strand;
  201. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  202. // && !defined(BOOST_ASIO_NO_TS_EXECUTORS)
  203. /// The type used to count the number of handlers executed by the context.
  204. typedef std::size_t count_type;
  205. /// Constructor.
  206. BOOST_ASIO_DECL io_context();
  207. /// Constructor.
  208. /**
  209. * @param a An allocator that will be used for allocating objects that are
  210. * associated with the context, such as services and internal state for I/O
  211. * objects.
  212. */
  213. template <typename Allocator>
  214. io_context(allocator_arg_t, const Allocator& a);
  215. /// Constructor.
  216. /**
  217. * Construct with a hint about the required level of concurrency.
  218. *
  219. * @param concurrency_hint A suggestion to the implementation on how many
  220. * threads it should allow to run simultaneously.
  221. */
  222. BOOST_ASIO_DECL explicit io_context(int concurrency_hint);
  223. /// Constructor.
  224. /**
  225. * Construct with a hint about the required level of concurrency.
  226. *
  227. * @param a An allocator that will be used for allocating objects that are
  228. * associated with the context, such as services and internal state for I/O
  229. * objects.
  230. *
  231. * @param concurrency_hint A suggestion to the implementation on how many
  232. * threads it should allow to run simultaneously.
  233. */
  234. template <typename Allocator>
  235. io_context(allocator_arg_t, const Allocator& a, int concurrency_hint);
  236. /// Constructor.
  237. /**
  238. * Construct with a service maker, to create an initial set of services that
  239. * will be installed into the execution context at construction time.
  240. *
  241. * @param initial_services Used to create the initial services. The @c make
  242. * function will be called once at the end of execution_context construction.
  243. */
  244. BOOST_ASIO_DECL explicit io_context(
  245. const execution_context::service_maker& initial_services);
  246. /// Constructor.
  247. /**
  248. * Construct with a service maker, to create an initial set of services that
  249. * will be installed into the execution context at construction time.
  250. *
  251. * @param a An allocator that will be used for allocating objects that are
  252. * associated with the context, such as services and internal state for I/O
  253. * objects.
  254. *
  255. * @param initial_services Used to create the initial services. The @c make
  256. * function will be called once at the end of execution_context construction.
  257. */
  258. template <typename Allocator>
  259. io_context(allocator_arg_t, const Allocator& a,
  260. const service_maker& initial_services);
  261. /// Destructor.
  262. /**
  263. * On destruction, the io_context performs the following sequence of
  264. * operations:
  265. *
  266. * @li For each service object @c svc in the io_context set, in reverse order
  267. * of the beginning of service object lifetime, performs
  268. * @c svc->shutdown().
  269. *
  270. * @li Uninvoked handler objects that were scheduled for deferred invocation
  271. * on the io_context, or any associated strand, are destroyed.
  272. *
  273. * @li For each service object @c svc in the io_context set, in reverse order
  274. * of the beginning of service object lifetime, performs
  275. * <tt>delete static_cast<io_context::service*>(svc)</tt>.
  276. *
  277. * @note The destruction sequence described above permits programs to
  278. * simplify their resource management by using @c shared_ptr<>. Where an
  279. * object's lifetime is tied to the lifetime of a connection (or some other
  280. * sequence of asynchronous operations), a @c shared_ptr to the object would
  281. * be bound into the handlers for all asynchronous operations associated with
  282. * it. This works as follows:
  283. *
  284. * @li When a single connection ends, all associated asynchronous operations
  285. * complete. The corresponding handler objects are destroyed, and all
  286. * @c shared_ptr references to the objects are destroyed.
  287. *
  288. * @li To shut down the whole program, the io_context function stop() is
  289. * called to terminate any run() calls as soon as possible. The io_context
  290. * destructor defined above destroys all handlers, causing all @c shared_ptr
  291. * references to all connection objects to be destroyed.
  292. */
  293. BOOST_ASIO_DECL ~io_context();
  294. /// Obtains the executor associated with the io_context.
  295. executor_type get_executor() noexcept;
  296. /// Run the io_context object's event processing loop.
  297. /**
  298. * The run() function blocks until all work has finished and there are no
  299. * more handlers to be dispatched, or until the io_context has been stopped.
  300. *
  301. * Multiple threads may call the run() function to set up a pool of threads
  302. * from which the io_context may execute handlers. All threads that are
  303. * waiting in the pool are equivalent and the io_context may choose any one
  304. * of them to invoke a handler.
  305. *
  306. * A normal exit from the run() function implies that the io_context object
  307. * is stopped (the stopped() function returns @c true). Subsequent calls to
  308. * run(), run_one(), poll() or poll_one() will return immediately unless there
  309. * is a prior call to restart().
  310. *
  311. * @return The number of handlers that were executed.
  312. *
  313. * @note Calling the run() function from a thread that is currently calling
  314. * one of run(), run_one(), run_for(), run_until(), poll() or poll_one() on
  315. * the same io_context object may introduce the potential for deadlock. It is
  316. * the caller's responsibility to avoid this.
  317. *
  318. * The poll() function may also be used to dispatch ready handlers, but
  319. * without blocking.
  320. */
  321. BOOST_ASIO_DECL count_type run();
  322. /// Run the io_context object's event processing loop for a specified
  323. /// duration.
  324. /**
  325. * The run_for() function blocks until all work has finished and there are no
  326. * more handlers to be dispatched, until the io_context has been stopped, or
  327. * until the specified duration has elapsed.
  328. *
  329. * @param rel_time The duration for which the call may block.
  330. *
  331. * @return The number of handlers that were executed.
  332. */
  333. template <typename Rep, typename Period>
  334. std::size_t run_for(const chrono::duration<Rep, Period>& rel_time);
  335. /// Run the io_context object's event processing loop until a specified time.
  336. /**
  337. * The run_until() function blocks until all work has finished and there are
  338. * no more handlers to be dispatched, until the io_context has been stopped,
  339. * or until the specified time has been reached.
  340. *
  341. * @param abs_time The time point until which the call may block.
  342. *
  343. * @return The number of handlers that were executed.
  344. */
  345. template <typename Clock, typename Duration>
  346. std::size_t run_until(const chrono::time_point<Clock, Duration>& abs_time);
  347. /// Run the io_context object's event processing loop to execute at most one
  348. /// handler.
  349. /**
  350. * The run_one() function blocks until one handler has been dispatched, or
  351. * until the io_context has been stopped.
  352. *
  353. * @return The number of handlers that were executed. A zero return value
  354. * implies that the io_context object is stopped (the stopped() function
  355. * returns @c true). Subsequent calls to run(), run_one(), poll() or
  356. * poll_one() will return immediately unless there is a prior call to
  357. * restart().
  358. *
  359. * @note Calling the run_one() function from a thread that is currently
  360. * calling one of run(), run_one(), run_for(), run_until(), poll() or
  361. * poll_one() on the same io_context object may introduce the potential for
  362. * deadlock. It is the caller's responsibility to avoid this.
  363. */
  364. BOOST_ASIO_DECL count_type run_one();
  365. /// Run the io_context object's event processing loop for a specified duration
  366. /// to execute at most one handler.
  367. /**
  368. * The run_one_for() function blocks until one handler has been dispatched,
  369. * until the io_context has been stopped, or until the specified duration has
  370. * elapsed.
  371. *
  372. * @param rel_time The duration for which the call may block.
  373. *
  374. * @return The number of handlers that were executed.
  375. */
  376. template <typename Rep, typename Period>
  377. std::size_t run_one_for(const chrono::duration<Rep, Period>& rel_time);
  378. /// Run the io_context object's event processing loop until a specified time
  379. /// to execute at most one handler.
  380. /**
  381. * The run_one_until() function blocks until one handler has been dispatched,
  382. * until the io_context has been stopped, or until the specified time has
  383. * been reached.
  384. *
  385. * @param abs_time The time point until which the call may block.
  386. *
  387. * @return The number of handlers that were executed.
  388. */
  389. template <typename Clock, typename Duration>
  390. std::size_t run_one_until(
  391. const chrono::time_point<Clock, Duration>& abs_time);
  392. /// Run the io_context object's event processing loop to execute ready
  393. /// handlers.
  394. /**
  395. * The poll() function runs handlers that are ready to run, without blocking,
  396. * until the io_context has been stopped or there are no more ready handlers.
  397. *
  398. * @return The number of handlers that were executed.
  399. */
  400. BOOST_ASIO_DECL count_type poll();
  401. /// Run the io_context object's event processing loop to execute one ready
  402. /// handler.
  403. /**
  404. * The poll_one() function runs at most one handler that is ready to run,
  405. * without blocking.
  406. *
  407. * @return The number of handlers that were executed.
  408. */
  409. BOOST_ASIO_DECL count_type poll_one();
  410. /// Stop the io_context object's event processing loop.
  411. /**
  412. * This function does not block, but instead simply signals the io_context to
  413. * stop. All invocations of its run() or run_one() member functions should
  414. * return as soon as possible. Subsequent calls to run(), run_one(), poll()
  415. * or poll_one() will return immediately until restart() is called.
  416. */
  417. BOOST_ASIO_DECL void stop();
  418. /// Determine whether the io_context object has been stopped.
  419. /**
  420. * This function is used to determine whether an io_context object has been
  421. * stopped, either through an explicit call to stop(), or due to running out
  422. * of work. When an io_context object is stopped, calls to run(), run_one(),
  423. * poll() or poll_one() will return immediately without invoking any
  424. * handlers.
  425. *
  426. * @return @c true if the io_context object is stopped, otherwise @c false.
  427. */
  428. BOOST_ASIO_DECL bool stopped() const;
  429. /// Restart the io_context in preparation for a subsequent run() invocation.
  430. /**
  431. * This function must be called prior to any second or later set of
  432. * invocations of the run(), run_one(), poll() or poll_one() functions when a
  433. * previous invocation of these functions returned due to the io_context
  434. * being stopped or running out of work. After a call to restart(), the
  435. * io_context object's stopped() function will return @c false.
  436. *
  437. * This function must not be called while there are any unfinished calls to
  438. * the run(), run_one(), poll() or poll_one() functions.
  439. */
  440. BOOST_ASIO_DECL void restart();
  441. #if !defined(BOOST_ASIO_NO_DEPRECATED)
  442. /// (Deprecated: Use boost::asio::bind_executor().) Create a new handler that
  443. /// automatically dispatches the wrapped handler on the io_context.
  444. /**
  445. * This function is used to create a new handler function object that, when
  446. * invoked, will automatically pass the wrapped handler to the io_context
  447. * object's dispatch function.
  448. *
  449. * @param handler The handler to be wrapped. The io_context will make a copy
  450. * of the handler object as required. The function signature of the handler
  451. * must be: @code void handler(A1 a1, ... An an); @endcode
  452. *
  453. * @return A function object that, when invoked, passes the wrapped handler to
  454. * the io_context object's dispatch function. Given a function object with the
  455. * signature:
  456. * @code R f(A1 a1, ... An an); @endcode
  457. * If this function object is passed to the wrap function like so:
  458. * @code io_context.wrap(f); @endcode
  459. * then the return value is a function object with the signature
  460. * @code void g(A1 a1, ... An an); @endcode
  461. * that, when invoked, executes code equivalent to:
  462. * @code boost::asio::dispatch(io_context,
  463. * boost::bind(f, a1, ... an)); @endcode
  464. */
  465. template <typename Handler>
  466. BOOST_ASIO_DEPRECATED_MSG("Use boost::asio::bind_executor()")
  467. #if defined(GENERATING_DOCUMENTATION)
  468. unspecified
  469. #else
  470. detail::wrapped_handler<io_context&, Handler>
  471. #endif
  472. wrap(Handler handler);
  473. #endif // !defined(BOOST_ASIO_NO_DEPRECATED)
  474. private:
  475. io_context(const io_context&) = delete;
  476. io_context& operator=(const io_context&) = delete;
  477. // Backwards compatible overload for use with services derived from
  478. // io_context::service.
  479. template <typename Service>
  480. friend Service& use_service(io_context& ioc);
  481. #if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
  482. detail::winsock_init<> init_;
  483. #elif defined(__sun) || defined(__QNX__) || defined(__hpux) || defined(_AIX) \
  484. || defined(__osf__)
  485. detail::signal_init<> init_;
  486. #endif
  487. // The implementation.
  488. impl_type& impl_;
  489. };
  490. /// Executor implementation type used to submit functions to an io_context.
  491. template <typename Allocator, uintptr_t Bits>
  492. class io_context::basic_executor_type :
  493. detail::io_context_bits, Allocator
  494. {
  495. public:
  496. /// Copy constructor.
  497. basic_executor_type(const basic_executor_type& other) noexcept
  498. : Allocator(static_cast<const Allocator&>(other)),
  499. target_(other.target_)
  500. {
  501. if (Bits & outstanding_work_tracked)
  502. if (context_ptr())
  503. context_ptr()->impl_.work_started();
  504. }
  505. /// Move constructor.
  506. basic_executor_type(basic_executor_type&& other) noexcept
  507. : Allocator(static_cast<Allocator&&>(other)),
  508. target_(other.target_)
  509. {
  510. if (Bits & outstanding_work_tracked)
  511. other.target_ = 0;
  512. }
  513. /// Destructor.
  514. ~basic_executor_type() noexcept
  515. {
  516. if (Bits & outstanding_work_tracked)
  517. if (context_ptr())
  518. context_ptr()->impl_.work_finished();
  519. }
  520. /// Assignment operator.
  521. basic_executor_type& operator=(const basic_executor_type& other) noexcept;
  522. /// Move assignment operator.
  523. basic_executor_type& operator=(basic_executor_type&& other) noexcept;
  524. #if !defined(GENERATING_DOCUMENTATION)
  525. private:
  526. friend struct boost_asio_require_fn::impl;
  527. friend struct boost_asio_prefer_fn::impl;
  528. #endif // !defined(GENERATING_DOCUMENTATION)
  529. /// Obtain an executor with the @c blocking.possibly property.
  530. /**
  531. * Do not call this function directly. It is intended for use with the
  532. * boost::asio::require customisation point.
  533. *
  534. * For example:
  535. * @code auto ex1 = my_io_context.get_executor();
  536. * auto ex2 = boost::asio::require(ex1,
  537. * boost::asio::execution::blocking.possibly); @endcode
  538. */
  539. constexpr basic_executor_type require(execution::blocking_t::possibly_t) const
  540. {
  541. return basic_executor_type(context_ptr(),
  542. *this, bits() & ~blocking_never);
  543. }
  544. /// Obtain an executor with the @c blocking.never property.
  545. /**
  546. * Do not call this function directly. It is intended for use with the
  547. * boost::asio::require customisation point.
  548. *
  549. * For example:
  550. * @code auto ex1 = my_io_context.get_executor();
  551. * auto ex2 = boost::asio::require(ex1,
  552. * boost::asio::execution::blocking.never); @endcode
  553. */
  554. constexpr basic_executor_type require(execution::blocking_t::never_t) const
  555. {
  556. return basic_executor_type(context_ptr(),
  557. *this, bits() | blocking_never);
  558. }
  559. /// Obtain an executor with the @c relationship.fork property.
  560. /**
  561. * Do not call this function directly. It is intended for use with the
  562. * boost::asio::require customisation point.
  563. *
  564. * For example:
  565. * @code auto ex1 = my_io_context.get_executor();
  566. * auto ex2 = boost::asio::require(ex1,
  567. * boost::asio::execution::relationship.fork); @endcode
  568. */
  569. constexpr basic_executor_type require(execution::relationship_t::fork_t) const
  570. {
  571. return basic_executor_type(context_ptr(),
  572. *this, bits() & ~relationship_continuation);
  573. }
  574. /// Obtain an executor with the @c relationship.continuation property.
  575. /**
  576. * Do not call this function directly. It is intended for use with the
  577. * boost::asio::require customisation point.
  578. *
  579. * For example:
  580. * @code auto ex1 = my_io_context.get_executor();
  581. * auto ex2 = boost::asio::require(ex1,
  582. * boost::asio::execution::relationship.continuation); @endcode
  583. */
  584. constexpr basic_executor_type require(
  585. execution::relationship_t::continuation_t) const
  586. {
  587. return basic_executor_type(context_ptr(),
  588. *this, bits() | relationship_continuation);
  589. }
  590. /// Obtain an executor with the @c outstanding_work.tracked property.
  591. /**
  592. * Do not call this function directly. It is intended for use with the
  593. * boost::asio::require customisation point.
  594. *
  595. * For example:
  596. * @code auto ex1 = my_io_context.get_executor();
  597. * auto ex2 = boost::asio::require(ex1,
  598. * boost::asio::execution::outstanding_work.tracked); @endcode
  599. */
  600. constexpr basic_executor_type<Allocator,
  601. BOOST_ASIO_UNSPECIFIED(Bits | outstanding_work_tracked)>
  602. require(execution::outstanding_work_t::tracked_t) const
  603. {
  604. return basic_executor_type<Allocator, Bits | outstanding_work_tracked>(
  605. context_ptr(), *this, bits());
  606. }
  607. /// Obtain an executor with the @c outstanding_work.untracked property.
  608. /**
  609. * Do not call this function directly. It is intended for use with the
  610. * boost::asio::require customisation point.
  611. *
  612. * For example:
  613. * @code auto ex1 = my_io_context.get_executor();
  614. * auto ex2 = boost::asio::require(ex1,
  615. * boost::asio::execution::outstanding_work.untracked); @endcode
  616. */
  617. constexpr basic_executor_type<Allocator,
  618. BOOST_ASIO_UNSPECIFIED(Bits & ~outstanding_work_tracked)>
  619. require(execution::outstanding_work_t::untracked_t) const
  620. {
  621. return basic_executor_type<Allocator, Bits & ~outstanding_work_tracked>(
  622. context_ptr(), *this, bits());
  623. }
  624. /// Obtain an executor with the specified @c allocator property.
  625. /**
  626. * Do not call this function directly. It is intended for use with the
  627. * boost::asio::require customisation point.
  628. *
  629. * For example:
  630. * @code auto ex1 = my_io_context.get_executor();
  631. * auto ex2 = boost::asio::require(ex1,
  632. * boost::asio::execution::allocator(my_allocator)); @endcode
  633. */
  634. template <typename OtherAllocator>
  635. constexpr basic_executor_type<OtherAllocator, Bits>
  636. require(execution::allocator_t<OtherAllocator> a) const
  637. {
  638. return basic_executor_type<OtherAllocator, Bits>(
  639. context_ptr(), a.value(), bits());
  640. }
  641. /// Obtain an executor with the default @c allocator property.
  642. /**
  643. * Do not call this function directly. It is intended for use with the
  644. * boost::asio::require customisation point.
  645. *
  646. * For example:
  647. * @code auto ex1 = my_io_context.get_executor();
  648. * auto ex2 = boost::asio::require(ex1,
  649. * boost::asio::execution::allocator); @endcode
  650. */
  651. constexpr basic_executor_type<std::allocator<void>, Bits>
  652. require(execution::allocator_t<void>) const
  653. {
  654. return basic_executor_type<std::allocator<void>, Bits>(
  655. context_ptr(), std::allocator<void>(), bits());
  656. }
  657. #if !defined(GENERATING_DOCUMENTATION)
  658. private:
  659. friend struct boost_asio_query_fn::impl;
  660. friend struct boost::asio::execution::detail::mapping_t<0>;
  661. friend struct boost::asio::execution::detail::inline_exception_handling_t<0>;
  662. friend struct boost::asio::execution::detail::outstanding_work_t<0>;
  663. #endif // !defined(GENERATING_DOCUMENTATION)
  664. /// Query the current value of the @c mapping property.
  665. /**
  666. * Do not call this function directly. It is intended for use with the
  667. * boost::asio::query customisation point.
  668. *
  669. * For example:
  670. * @code auto ex = my_io_context.get_executor();
  671. * if (boost::asio::query(ex, boost::asio::execution::mapping)
  672. * == boost::asio::execution::mapping.thread)
  673. * ... @endcode
  674. */
  675. static constexpr execution::mapping_t query(execution::mapping_t) noexcept
  676. {
  677. return execution::mapping.thread;
  678. }
  679. /// Query the current value of the @c inline_exception_handling property.
  680. /**
  681. * Do not call this function directly. It is intended for use with the
  682. * boost::asio::query customisation point.
  683. *
  684. * For example:
  685. * @code auto ex = my_io_context.get_executor();
  686. * if (boost::asio::query(ex,
  687. * boost::asio::execution::inline_exception_handling)
  688. * == boost::asio::execution::inline_exception_handling.capture)
  689. * ... @endcode
  690. */
  691. static constexpr execution::inline_exception_handling_t query(
  692. execution::inline_exception_handling_t) noexcept
  693. {
  694. return execution::inline_exception_handling.capture;
  695. }
  696. /// Query the current value of the @c context property.
  697. /**
  698. * Do not call this function directly. It is intended for use with the
  699. * boost::asio::query customisation point.
  700. *
  701. * For example:
  702. * @code auto ex = my_io_context.get_executor();
  703. * boost::asio::io_context& ctx = boost::asio::query(
  704. * ex, boost::asio::execution::context); @endcode
  705. */
  706. io_context& query(execution::context_t) const noexcept
  707. {
  708. return *context_ptr();
  709. }
  710. /// Query the current value of the @c blocking property.
  711. /**
  712. * Do not call this function directly. It is intended for use with the
  713. * boost::asio::query customisation point.
  714. *
  715. * For example:
  716. * @code auto ex = my_io_context.get_executor();
  717. * if (boost::asio::query(ex, boost::asio::execution::blocking)
  718. * == boost::asio::execution::blocking.always)
  719. * ... @endcode
  720. */
  721. constexpr execution::blocking_t query(execution::blocking_t) const noexcept
  722. {
  723. return (bits() & blocking_never)
  724. ? execution::blocking_t(execution::blocking.never)
  725. : execution::blocking_t(execution::blocking.possibly);
  726. }
  727. /// Query the current value of the @c relationship property.
  728. /**
  729. * Do not call this function directly. It is intended for use with the
  730. * boost::asio::query customisation point.
  731. *
  732. * For example:
  733. * @code auto ex = my_io_context.get_executor();
  734. * if (boost::asio::query(ex, boost::asio::execution::relationship)
  735. * == boost::asio::execution::relationship.continuation)
  736. * ... @endcode
  737. */
  738. constexpr execution::relationship_t query(
  739. execution::relationship_t) const noexcept
  740. {
  741. return (bits() & relationship_continuation)
  742. ? execution::relationship_t(execution::relationship.continuation)
  743. : execution::relationship_t(execution::relationship.fork);
  744. }
  745. /// Query the current value of the @c outstanding_work property.
  746. /**
  747. * Do not call this function directly. It is intended for use with the
  748. * boost::asio::query customisation point.
  749. *
  750. * For example:
  751. * @code auto ex = my_io_context.get_executor();
  752. * if (boost::asio::query(ex, boost::asio::execution::outstanding_work)
  753. * == boost::asio::execution::outstanding_work.tracked)
  754. * ... @endcode
  755. */
  756. static constexpr execution::outstanding_work_t query(
  757. execution::outstanding_work_t) noexcept
  758. {
  759. return (Bits & outstanding_work_tracked)
  760. ? execution::outstanding_work_t(execution::outstanding_work.tracked)
  761. : execution::outstanding_work_t(execution::outstanding_work.untracked);
  762. }
  763. /// Query the current value of the @c allocator property.
  764. /**
  765. * Do not call this function directly. It is intended for use with the
  766. * boost::asio::query customisation point.
  767. *
  768. * For example:
  769. * @code auto ex = my_io_context.get_executor();
  770. * auto alloc = boost::asio::query(ex,
  771. * boost::asio::execution::allocator); @endcode
  772. */
  773. template <typename OtherAllocator>
  774. constexpr Allocator query(
  775. execution::allocator_t<OtherAllocator>) const noexcept
  776. {
  777. return static_cast<const Allocator&>(*this);
  778. }
  779. /// Query the current value of the @c allocator property.
  780. /**
  781. * Do not call this function directly. It is intended for use with the
  782. * boost::asio::query customisation point.
  783. *
  784. * For example:
  785. * @code auto ex = my_io_context.get_executor();
  786. * auto alloc = boost::asio::query(ex,
  787. * boost::asio::execution::allocator); @endcode
  788. */
  789. constexpr Allocator query(execution::allocator_t<void>) const noexcept
  790. {
  791. return static_cast<const Allocator&>(*this);
  792. }
  793. public:
  794. /// Determine whether the io_context is running in the current thread.
  795. /**
  796. * @return @c true if the current thread is running the io_context. Otherwise
  797. * returns @c false.
  798. */
  799. bool running_in_this_thread() const noexcept;
  800. /// Compare two executors for equality.
  801. /**
  802. * Two executors are equal if they refer to the same underlying io_context.
  803. */
  804. friend bool operator==(const basic_executor_type& a,
  805. const basic_executor_type& b) noexcept
  806. {
  807. return a.target_ == b.target_
  808. && static_cast<const Allocator&>(a) == static_cast<const Allocator&>(b);
  809. }
  810. /// Compare two executors for inequality.
  811. /**
  812. * Two executors are equal if they refer to the same underlying io_context.
  813. */
  814. friend bool operator!=(const basic_executor_type& a,
  815. const basic_executor_type& b) noexcept
  816. {
  817. return a.target_ != b.target_
  818. || static_cast<const Allocator&>(a) != static_cast<const Allocator&>(b);
  819. }
  820. /// Execution function.
  821. template <typename Function>
  822. void execute(Function&& f) const;
  823. #if !defined(BOOST_ASIO_NO_TS_EXECUTORS)
  824. public:
  825. /// Obtain the underlying execution context.
  826. io_context& context() const noexcept;
  827. /// Inform the io_context that it has some outstanding work to do.
  828. /**
  829. * This function is used to inform the io_context that some work has begun.
  830. * This ensures that the io_context's run() and run_one() functions do not
  831. * exit while the work is underway.
  832. */
  833. void on_work_started() const noexcept;
  834. /// Inform the io_context that some work is no longer outstanding.
  835. /**
  836. * This function is used to inform the io_context that some work has
  837. * finished. Once the count of unfinished work reaches zero, the io_context
  838. * is stopped and the run() and run_one() functions may exit.
  839. */
  840. void on_work_finished() const noexcept;
  841. /// Request the io_context to invoke the given function object.
  842. /**
  843. * This function is used to ask the io_context to execute the given function
  844. * object. If the current thread is running the io_context, @c dispatch()
  845. * executes the function before returning. Otherwise, the function will be
  846. * scheduled to run on the io_context.
  847. *
  848. * @param f The function object to be called. The executor will make a copy
  849. * of the handler object as required. The function signature of the function
  850. * object must be: @code void function(); @endcode
  851. *
  852. * @param a An allocator that may be used by the executor to allocate the
  853. * internal storage needed for function invocation.
  854. */
  855. template <typename Function, typename OtherAllocator>
  856. void dispatch(Function&& f, const OtherAllocator& a) const;
  857. /// Request the io_context to invoke the given function object.
  858. /**
  859. * This function is used to ask the io_context to execute the given function
  860. * object. The function object will never be executed inside @c post().
  861. * Instead, it will be scheduled to run on the io_context.
  862. *
  863. * @param f The function object to be called. The executor will make a copy
  864. * of the handler object as required. The function signature of the function
  865. * object must be: @code void function(); @endcode
  866. *
  867. * @param a An allocator that may be used by the executor to allocate the
  868. * internal storage needed for function invocation.
  869. */
  870. template <typename Function, typename OtherAllocator>
  871. void post(Function&& f, const OtherAllocator& a) const;
  872. /// Request the io_context to invoke the given function object.
  873. /**
  874. * This function is used to ask the io_context to execute the given function
  875. * object. The function object will never be executed inside @c defer().
  876. * Instead, it will be scheduled to run on the io_context.
  877. *
  878. * If the current thread belongs to the io_context, @c defer() will delay
  879. * scheduling the function object until the current thread returns control to
  880. * the pool.
  881. *
  882. * @param f The function object to be called. The executor will make a copy
  883. * of the handler object as required. The function signature of the function
  884. * object must be: @code void function(); @endcode
  885. *
  886. * @param a An allocator that may be used by the executor to allocate the
  887. * internal storage needed for function invocation.
  888. */
  889. template <typename Function, typename OtherAllocator>
  890. void defer(Function&& f, const OtherAllocator& a) const;
  891. #endif // !defined(BOOST_ASIO_NO_TS_EXECUTORS)
  892. private:
  893. friend class io_context;
  894. template <typename, uintptr_t> friend class basic_executor_type;
  895. // Constructor used by io_context::get_executor().
  896. explicit basic_executor_type(io_context& i) noexcept
  897. : Allocator(),
  898. target_(reinterpret_cast<uintptr_t>(&i))
  899. {
  900. if (Bits & outstanding_work_tracked)
  901. context_ptr()->impl_.work_started();
  902. }
  903. // Constructor used by require().
  904. basic_executor_type(io_context* i,
  905. const Allocator& a, uintptr_t bits) noexcept
  906. : Allocator(a),
  907. target_(reinterpret_cast<uintptr_t>(i) | bits)
  908. {
  909. if (Bits & outstanding_work_tracked)
  910. if (context_ptr())
  911. context_ptr()->impl_.work_started();
  912. }
  913. io_context* context_ptr() const noexcept
  914. {
  915. return reinterpret_cast<io_context*>(target_ & ~runtime_bits);
  916. }
  917. uintptr_t bits() const noexcept
  918. {
  919. return target_ & runtime_bits;
  920. }
  921. // The underlying io_context and runtime bits.
  922. uintptr_t target_;
  923. };
  924. /// Base class for all io_context services.
  925. class io_context::service
  926. : public execution_context::service
  927. {
  928. public:
  929. /// Get the io_context object that owns the service.
  930. boost::asio::io_context& get_io_context();
  931. private:
  932. /// Destroy all user-defined handler objects owned by the service.
  933. BOOST_ASIO_DECL virtual void shutdown();
  934. /// Handle notification of a fork-related event to perform any necessary
  935. /// housekeeping.
  936. /**
  937. * This function is not a pure virtual so that services only have to
  938. * implement it if necessary. The default implementation does nothing.
  939. */
  940. BOOST_ASIO_DECL virtual void notify_fork(
  941. execution_context::fork_event event);
  942. protected:
  943. /// Constructor.
  944. /**
  945. * @param owner The io_context object that owns the service.
  946. */
  947. BOOST_ASIO_DECL service(boost::asio::io_context& owner);
  948. /// Destructor.
  949. BOOST_ASIO_DECL virtual ~service();
  950. };
  951. namespace detail {
  952. // Special service base class to keep classes header-file only.
  953. template <typename Type>
  954. class service_base
  955. : public boost::asio::io_context::service
  956. {
  957. public:
  958. static boost::asio::detail::service_id<Type> id;
  959. // Constructor.
  960. service_base(boost::asio::io_context& io_context)
  961. : boost::asio::io_context::service(io_context)
  962. {
  963. }
  964. };
  965. template <typename Type>
  966. boost::asio::detail::service_id<Type> service_base<Type>::id;
  967. } // namespace detail
  968. #if !defined(GENERATING_DOCUMENTATION)
  969. namespace traits {
  970. #if !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  971. template <typename Allocator, uintptr_t Bits>
  972. struct equality_comparable<
  973. boost::asio::io_context::basic_executor_type<Allocator, Bits>
  974. >
  975. {
  976. static constexpr bool is_valid = true;
  977. static constexpr bool is_noexcept = true;
  978. };
  979. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  980. #if !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  981. template <typename Allocator, uintptr_t Bits, typename Function>
  982. struct execute_member<
  983. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  984. Function
  985. >
  986. {
  987. static constexpr bool is_valid = true;
  988. static constexpr bool is_noexcept = false;
  989. typedef void result_type;
  990. };
  991. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  992. #if !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
  993. template <typename Allocator, uintptr_t Bits>
  994. struct require_member<
  995. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  996. boost::asio::execution::blocking_t::possibly_t
  997. >
  998. {
  999. static constexpr bool is_valid = true;
  1000. static constexpr bool is_noexcept = false;
  1001. typedef boost::asio::io_context::basic_executor_type<
  1002. Allocator, Bits> result_type;
  1003. };
  1004. template <typename Allocator, uintptr_t Bits>
  1005. struct require_member<
  1006. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1007. boost::asio::execution::blocking_t::never_t
  1008. >
  1009. {
  1010. static constexpr bool is_valid = true;
  1011. static constexpr bool is_noexcept = false;
  1012. typedef boost::asio::io_context::basic_executor_type<
  1013. Allocator, Bits> result_type;
  1014. };
  1015. template <typename Allocator, uintptr_t Bits>
  1016. struct require_member<
  1017. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1018. boost::asio::execution::relationship_t::fork_t
  1019. >
  1020. {
  1021. static constexpr bool is_valid = true;
  1022. static constexpr bool is_noexcept = false;
  1023. typedef boost::asio::io_context::basic_executor_type<
  1024. Allocator, Bits> result_type;
  1025. };
  1026. template <typename Allocator, uintptr_t Bits>
  1027. struct require_member<
  1028. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1029. boost::asio::execution::relationship_t::continuation_t
  1030. >
  1031. {
  1032. static constexpr bool is_valid = true;
  1033. static constexpr bool is_noexcept = false;
  1034. typedef boost::asio::io_context::basic_executor_type<
  1035. Allocator, Bits> result_type;
  1036. };
  1037. template <typename Allocator, uintptr_t Bits>
  1038. struct require_member<
  1039. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1040. boost::asio::execution::outstanding_work_t::tracked_t
  1041. > : boost::asio::detail::io_context_bits
  1042. {
  1043. static constexpr bool is_valid = true;
  1044. static constexpr bool is_noexcept = false;
  1045. typedef boost::asio::io_context::basic_executor_type<
  1046. Allocator, Bits | outstanding_work_tracked> result_type;
  1047. };
  1048. template <typename Allocator, uintptr_t Bits>
  1049. struct require_member<
  1050. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1051. boost::asio::execution::outstanding_work_t::untracked_t
  1052. > : boost::asio::detail::io_context_bits
  1053. {
  1054. static constexpr bool is_valid = true;
  1055. static constexpr bool is_noexcept = false;
  1056. typedef boost::asio::io_context::basic_executor_type<
  1057. Allocator, Bits & ~outstanding_work_tracked> result_type;
  1058. };
  1059. template <typename Allocator, uintptr_t Bits>
  1060. struct require_member<
  1061. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1062. boost::asio::execution::allocator_t<void>
  1063. >
  1064. {
  1065. static constexpr bool is_valid = true;
  1066. static constexpr bool is_noexcept = false;
  1067. typedef boost::asio::io_context::basic_executor_type<
  1068. std::allocator<void>, Bits> result_type;
  1069. };
  1070. template <uintptr_t Bits,
  1071. typename Allocator, typename OtherAllocator>
  1072. struct require_member<
  1073. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1074. boost::asio::execution::allocator_t<OtherAllocator>
  1075. >
  1076. {
  1077. static constexpr bool is_valid = true;
  1078. static constexpr bool is_noexcept = false;
  1079. typedef boost::asio::io_context::basic_executor_type<
  1080. OtherAllocator, Bits> result_type;
  1081. };
  1082. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_REQUIRE_MEMBER_TRAIT)
  1083. #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  1084. template <typename Allocator, uintptr_t Bits, typename Property>
  1085. struct query_static_constexpr_member<
  1086. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1087. Property,
  1088. typename boost::asio::enable_if<
  1089. boost::asio::is_convertible<
  1090. Property,
  1091. boost::asio::execution::outstanding_work_t
  1092. >::value
  1093. >::type
  1094. > : boost::asio::detail::io_context_bits
  1095. {
  1096. static constexpr bool is_valid = true;
  1097. static constexpr bool is_noexcept = true;
  1098. typedef boost::asio::execution::outstanding_work_t result_type;
  1099. static constexpr result_type value() noexcept
  1100. {
  1101. return (Bits & outstanding_work_tracked)
  1102. ? execution::outstanding_work_t(execution::outstanding_work.tracked)
  1103. : execution::outstanding_work_t(execution::outstanding_work.untracked);
  1104. }
  1105. };
  1106. template <typename Allocator, uintptr_t Bits, typename Property>
  1107. struct query_static_constexpr_member<
  1108. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1109. Property,
  1110. typename boost::asio::enable_if<
  1111. boost::asio::is_convertible<
  1112. Property,
  1113. boost::asio::execution::mapping_t
  1114. >::value
  1115. >::type
  1116. >
  1117. {
  1118. static constexpr bool is_valid = true;
  1119. static constexpr bool is_noexcept = true;
  1120. typedef boost::asio::execution::mapping_t::thread_t result_type;
  1121. static constexpr result_type value() noexcept
  1122. {
  1123. return result_type();
  1124. }
  1125. };
  1126. template <typename Allocator, uintptr_t Bits, typename Property>
  1127. struct query_static_constexpr_member<
  1128. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1129. Property,
  1130. typename boost::asio::enable_if<
  1131. boost::asio::is_convertible<
  1132. Property,
  1133. boost::asio::execution::inline_exception_handling_t
  1134. >::value
  1135. >::type
  1136. >
  1137. {
  1138. static constexpr bool is_valid = true;
  1139. static constexpr bool is_noexcept = true;
  1140. typedef boost::asio::execution::inline_exception_handling_t::capture_t
  1141. result_type;
  1142. static constexpr result_type value() noexcept
  1143. {
  1144. return result_type();
  1145. }
  1146. };
  1147. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
  1148. #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  1149. template <typename Allocator, uintptr_t Bits, typename Property>
  1150. struct query_member<
  1151. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1152. Property,
  1153. typename boost::asio::enable_if<
  1154. boost::asio::is_convertible<
  1155. Property,
  1156. boost::asio::execution::blocking_t
  1157. >::value
  1158. >::type
  1159. >
  1160. {
  1161. static constexpr bool is_valid = true;
  1162. static constexpr bool is_noexcept = true;
  1163. typedef boost::asio::execution::blocking_t result_type;
  1164. };
  1165. template <typename Allocator, uintptr_t Bits, typename Property>
  1166. struct query_member<
  1167. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1168. Property,
  1169. typename boost::asio::enable_if<
  1170. boost::asio::is_convertible<
  1171. Property,
  1172. boost::asio::execution::relationship_t
  1173. >::value
  1174. >::type
  1175. >
  1176. {
  1177. static constexpr bool is_valid = true;
  1178. static constexpr bool is_noexcept = true;
  1179. typedef boost::asio::execution::relationship_t result_type;
  1180. };
  1181. template <typename Allocator, uintptr_t Bits>
  1182. struct query_member<
  1183. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1184. boost::asio::execution::context_t
  1185. >
  1186. {
  1187. static constexpr bool is_valid = true;
  1188. static constexpr bool is_noexcept = true;
  1189. typedef boost::asio::io_context& result_type;
  1190. };
  1191. template <typename Allocator, uintptr_t Bits>
  1192. struct query_member<
  1193. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1194. boost::asio::execution::allocator_t<void>
  1195. >
  1196. {
  1197. static constexpr bool is_valid = true;
  1198. static constexpr bool is_noexcept = true;
  1199. typedef Allocator result_type;
  1200. };
  1201. template <typename Allocator, uintptr_t Bits, typename OtherAllocator>
  1202. struct query_member<
  1203. boost::asio::io_context::basic_executor_type<Allocator, Bits>,
  1204. boost::asio::execution::allocator_t<OtherAllocator>
  1205. >
  1206. {
  1207. static constexpr bool is_valid = true;
  1208. static constexpr bool is_noexcept = true;
  1209. typedef Allocator result_type;
  1210. };
  1211. #endif // !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
  1212. } // namespace traits
  1213. namespace execution {
  1214. template <>
  1215. struct is_executor<io_context> : false_type
  1216. {
  1217. };
  1218. } // namespace execution
  1219. #endif // !defined(GENERATING_DOCUMENTATION)
  1220. } // namespace asio
  1221. } // namespace boost
  1222. #include <boost/asio/detail/pop_options.hpp>
  1223. #include <boost/asio/impl/io_context.hpp>
  1224. #if defined(BOOST_ASIO_HEADER_ONLY)
  1225. # include <boost/asio/impl/io_context.ipp>
  1226. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  1227. // If both io_context.hpp and strand.hpp have been included, automatically
  1228. // include the header file needed for the io_context::strand class.
  1229. #if !defined(BOOST_ASIO_NO_EXTENSIONS)
  1230. # if defined(BOOST_ASIO_STRAND_HPP)
  1231. # include <boost/asio/io_context_strand.hpp>
  1232. # endif // defined(BOOST_ASIO_STRAND_HPP)
  1233. #endif // !defined(BOOST_ASIO_NO_EXTENSIONS)
  1234. #endif // BOOST_ASIO_IO_CONTEXT_HPP