From: Adam C. Emerson Date: Tue, 10 Nov 2020 01:59:13 +0000 (-0500) Subject: common/async: Hold lock in constructor of blocked_result X-Git-Tag: v16.1.0~182^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=583da3d588ee43a3b613ba6df82c4845043ad1da;p=ceph.git common/async: Hold lock in constructor of blocked_result More correct, though not the cause of error. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/async/blocked_completion.h b/src/common/async/blocked_completion.h index 633e01ecf5eb..23a1319bc0fa 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;