Don't use removed boost::asio::spawn() overload if Boost >= v1.87

This commit is contained in:
Alexander A. Klimov 2025-03-07 15:47:37 +01:00 committed by Julian Brost
parent 0662f2b719
commit fb2b2e2d5b
2 changed files with 18 additions and 5 deletions

View File

@ -16,11 +16,16 @@
#include <utility>
#include <vector>
#include <stdexcept>
#include <boost/context/fixedsize_stack.hpp>
#include <boost/exception/all.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/spawn.hpp>
#if BOOST_VERSION >= 108700
# include <boost/asio/detached.hpp>
#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
);
}

View File

@ -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);
{