From 583da3d588ee43a3b613ba6df82c4845043ad1da Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Mon, 9 Nov 2020 20:59:13 -0500 Subject: [PATCH] common/async: Hold lock in constructor of blocked_result More correct, though not the cause of error. Signed-off-by: Adam C. Emerson --- src/common/async/blocked_completion.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/common/async/blocked_completion.h b/src/common/async/blocked_completion.h index 633e01ecf5eb9..23a1319bc0fa3 100644 --- a/src/common/async/blocked_completion.h +++ b/src/common/async/blocked_completion.h @@ -129,7 +129,6 @@ struct blocked_handler bool* done = nullptr; }; - template class blocked_result { @@ -138,6 +137,7 @@ public: using return_type = std::tuple; explicit blocked_result(completion_handler_type& h) noexcept { + std::scoped_lock l(m); out_ec = h.ec; if (!out_ec) h.ec = &ec; h.value = &value; @@ -153,6 +153,11 @@ public: return std::move(*value); } + blocked_result(const blocked_result&) = delete; + blocked_result& operator =(const blocked_result&) = delete; + blocked_result(blocked_result&&) = delete; + blocked_result& operator =(blocked_result&&) = delete; + private: bs::error_code* out_ec; bs::error_code ec; @@ -170,6 +175,7 @@ public: using return_type = T; explicit blocked_result(completion_handler_type& h) noexcept { + std::scoped_lock l(m); out_ec = h.ec; if (!out_ec) h.ec = &ec; h.value = &value; @@ -185,6 +191,11 @@ public: return std::move(*value); } + blocked_result(const blocked_result&) = delete; + blocked_result& operator =(const blocked_result&) = delete; + blocked_result(blocked_result&&) = delete; + blocked_result& operator =(blocked_result&&) = delete; + private: bs::error_code* out_ec; bs::error_code ec; @@ -202,6 +213,7 @@ public: using return_type = void; explicit blocked_result(completion_handler_type& h) noexcept { + std::scoped_lock l(m); out_ec = h.ec; if (!out_ec) h.ec = &ec; h.m = &m; @@ -215,6 +227,11 @@ public: if (!out_ec && ec) throw bs::system_error(ec); } + blocked_result(const blocked_result&) = delete; + blocked_result& operator =(const blocked_result&) = delete; + blocked_result(blocked_result&&) = delete; + blocked_result& operator =(blocked_result&&) = delete; + private: bs::error_code* out_ec; bs::error_code ec; -- 2.39.5