From ba0e4e45bcc60b6897cd5c8f96cc404981e5c2c2 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Tue, 2 Jun 2015 13:22:35 +0300 Subject: [PATCH] future: disable inline continuations in debug mode Inline continuations can hide bugs where a stack variable is captured by reference. Disable them in debug mode. --- core/future.hh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/future.hh b/core/future.hh index 625fc35cc2..62f6ed12cf 100644 --- a/core/future.hh +++ b/core/future.hh @@ -327,6 +327,13 @@ struct continuation final : task { future_state _state; Func _func; }; + +#ifndef DEBUG +static constexpr unsigned max_inlined_continuations = 256; +#else +static constexpr unsigned max_inlined_continuations = 1; +#endif + /// \endcond /// \brief promise - allows a future value to be made available at a later time. @@ -586,7 +593,7 @@ private: futurize_t then(Func&& func, Param&& param) noexcept { using futurator = futurize; using P = typename futurator::promise_type; - if (state()->available() && (++future_avail_count % 256)) { + if (state()->available() && (++future_avail_count % max_inlined_continuations)) { try { return futurator::apply(std::forward(func), param(std::move(*state()))); } catch (...) {