mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 15:14:07 +02:00
Avoid multiple #if in a single function call expression
Simply giving two entire call expressions for either Boost version greatly improves readability in my opinion.
This commit is contained in:
parent
ccfc72267f
commit
d1d399f8b3
@ -105,35 +105,32 @@ public:
|
|||||||
|
|
||||||
template <typename Handler, typename Function>
|
template <typename Handler, typename Function>
|
||||||
static void SpawnCoroutine(Handler& h, Function f) {
|
static void SpawnCoroutine(Handler& h, Function f) {
|
||||||
|
auto wrapper = [f](boost::asio::yield_context yc) {
|
||||||
boost::asio::spawn(h,
|
try {
|
||||||
#if BOOST_VERSION >= 108700
|
f(yc);
|
||||||
std::allocator_arg,
|
} catch (const std::exception& ex) {
|
||||||
boost::context::fixedsize_stack(GetCoroutineStackSize()),
|
Log(LogCritical, "IoEngine") << "Exception in coroutine: " << DiagnosticInformation(ex);
|
||||||
#endif // BOOST_VERSION >= 108700
|
} catch (...) {
|
||||||
[f](boost::asio::yield_context yc) {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
f(yc);
|
Log(LogCritical, "IoEngine", "Exception in coroutine!");
|
||||||
} catch (const std::exception& ex) {
|
|
||||||
Log(LogCritical, "IoEngine") << "Exception in coroutine: " << DiagnosticInformation(ex);
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
try {
|
|
||||||
Log(LogCritical, "IoEngine", "Exception in coroutine!");
|
|
||||||
} catch (...) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Required for proper stack unwinding when coroutines are destroyed.
|
|
||||||
// https://github.com/boostorg/coroutine/issues/39
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
// Required for proper stack unwinding when coroutines are destroyed.
|
||||||
|
// https://github.com/boostorg/coroutine/issues/39
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#if BOOST_VERSION >= 108700
|
#if BOOST_VERSION >= 108700
|
||||||
|
boost::asio::spawn(h,
|
||||||
|
std::allocator_arg, boost::context::fixedsize_stack(GetCoroutineStackSize()),
|
||||||
|
std::move(wrapper),
|
||||||
boost::asio::detached
|
boost::asio::detached
|
||||||
#else // BOOST_VERSION >= 108700
|
|
||||||
boost::coroutines::attributes(GetCoroutineStackSize()) // Set a pre-defined stack size.
|
|
||||||
#endif // BOOST_VERSION >= 108700
|
|
||||||
);
|
);
|
||||||
|
#else // BOOST_VERSION >= 108700
|
||||||
|
boost::asio::spawn(h, std::move(wrapper), boost::coroutines::attributes(GetCoroutineStackSize()));
|
||||||
|
#endif // BOOST_VERSION >= 108700
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
|
Loading…
x
Reference in New Issue
Block a user