From fb2b2e2d5b32a02309aa1c50ae5e9fb873922988 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 7 Mar 2025 15:47:37 +0100 Subject: [PATCH] Don't use removed boost::asio::spawn() overload if Boost >= v1.87 --- lib/base/io-engine.hpp | 13 +++++++++++++ test/base-io-engine.cpp | 10 +++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/base/io-engine.hpp b/lib/base/io-engine.hpp index 55a06fb6a..2083b62f8 100644 --- a/lib/base/io-engine.hpp +++ b/lib/base/io-engine.hpp @@ -16,11 +16,16 @@ #include #include #include +#include #include #include #include #include +#if BOOST_VERSION >= 108700 +# include +#endif // BOOST_VERSION >= 108700 + namespace icinga { @@ -102,6 +107,10 @@ public: static void SpawnCoroutine(Handler& h, Function f) { boost::asio::spawn(h, +#if BOOST_VERSION >= 108700 + std::allocator_arg, + boost::context::fixedsize_stack(GetCoroutineStackSize()), +#endif // BOOST_VERSION >= 108700 [f](boost::asio::yield_context yc) { try { @@ -119,7 +128,11 @@ public: throw; } }, +#if BOOST_VERSION >= 108700 + boost::asio::detached +#else // BOOST_VERSION >= 108700 boost::coroutines::attributes(GetCoroutineStackSize()) // Set a pre-defined stack size. +#endif // BOOST_VERSION >= 108700 ); } diff --git a/test/base-io-engine.cpp b/test/base-io-engine.cpp index 869688b1a..3a251b1b4 100644 --- a/test/base-io-engine.cpp +++ b/test/base-io-engine.cpp @@ -17,7 +17,7 @@ BOOST_AUTO_TEST_CASE(timeout_run) boost::asio::io_context::strand strand (io); int called = 0; - boost::asio::spawn(strand, [&](boost::asio::yield_context yc) { + IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) { boost::asio::deadline_timer timer (io); Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; }); @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(timeout_cancelled) boost::asio::io_context::strand strand (io); int called = 0; - boost::asio::spawn(strand, [&](boost::asio::yield_context yc) { + IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) { boost::asio::deadline_timer timer (io); Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; }); @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE(timeout_scope) boost::asio::io_context::strand strand (io); int called = 0; - boost::asio::spawn(strand, [&](boost::asio::yield_context yc) { + IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) { boost::asio::deadline_timer timer (io); { @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_cancelled) boost::asio::io_context::strand strand (io); int called = 0; - boost::asio::spawn(strand, [&](boost::asio::yield_context yc) { + IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) { boost::asio::deadline_timer timer (io); Timeout timeout (strand, boost::posix_time::millisec(300), [&called] { ++called; }); @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(timeout_due_scope) boost::asio::io_context::strand strand (io); int called = 0; - boost::asio::spawn(strand, [&](boost::asio::yield_context yc) { + IoEngine::SpawnCoroutine(strand, [&](boost::asio::yield_context yc) { boost::asio::deadline_timer timer (io); {