From: Radoslaw Zarzynski Date: Fri, 8 Mar 2019 00:31:10 +0000 (+0100) Subject: msg/async: avoid extra pointers in continuation definitions. X-Git-Tag: v14.2.0~23^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0d47daee691dc1a4ae85b2a1af58bd86a3ab606f;p=ceph.git msg/async: avoid extra pointers in continuation definitions. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/msg/async/Protocol.h b/src/msg/async/Protocol.h index e971448532e1..b4a29814c538 100644 --- a/src/msg/async/Protocol.h +++ b/src/msg/async/Protocol.h @@ -47,21 +47,19 @@ public: }; #define CONTINUATION_DECL(C, F, ...) \ - std::unique_ptr> F##_cont_ = \ - std::make_unique>(&C::F); \ - CtFun *F##_cont = F##_cont_.get() + CtFun F##_cont { (&C::F) }; -#define CONTINUATION_PARAM(V, C, ...) CtFun *V##_cont +#define CONTINUATION_PARAM(V, C, ...) CtFun &V##_cont #define CONTINUATION(F) F##_cont -#define CONTINUE(F, ...) F##_cont->setParams(__VA_ARGS__), F##_cont +#define CONTINUE(F, ...) (F##_cont.setParams(__VA_ARGS__), &F##_cont) #define CONTINUATION_RUN(CT) \ { \ - Ct::type> *_cont = CT; \ - while (_cont) { \ + Ct::type> *_cont = &CT;\ + do { \ _cont = _cont->call(this); \ - } \ + } while (_cont); \ } #define READ_HANDLER_CONTINUATION_DECL(C, F) \ diff --git a/src/msg/async/ProtocolV1.cc b/src/msg/async/ProtocolV1.cc index 3857ed5c14d0..e7aeb4f197a3 100644 --- a/src/msg/async/ProtocolV1.cc +++ b/src/msg/async/ProtocolV1.cc @@ -408,8 +408,10 @@ bool ProtocolV1::is_queued() { return !out_q.empty() || connection->is_queued(); } -void ProtocolV1::run_continuation(CtPtr continuation) { - CONTINUATION_RUN(continuation); +void ProtocolV1::run_continuation(CtPtr pcontinuation) { + if (pcontinuation) { + CONTINUATION_RUN(*pcontinuation); + } } CtPtr ProtocolV1::read(CONTINUATION_PARAM(next, ProtocolV1, char *, int), @@ -418,8 +420,8 @@ CtPtr ProtocolV1::read(CONTINUATION_PARAM(next, ProtocolV1, char *, int), buffer = temp_buffer; } ssize_t r = connection->read(len, buffer, - [CONTINUATION(next), this](char *buffer, int r) { - CONTINUATION(next)->setParams(buffer, r); + [&CONTINUATION(next), this](char *buffer, int r) { + CONTINUATION(next).setParams(buffer, r); CONTINUATION_RUN(CONTINUATION(next)); }); if (r <= 0) { @@ -431,8 +433,8 @@ CtPtr ProtocolV1::read(CONTINUATION_PARAM(next, ProtocolV1, char *, int), CtPtr ProtocolV1::write(CONTINUATION_PARAM(next, ProtocolV1, int), bufferlist &buffer) { - ssize_t r = connection->write(buffer, [CONTINUATION(next), this](int r) { - CONTINUATION(next)->setParams(r); + ssize_t r = connection->write(buffer, [&CONTINUATION(next), this](int r) { + CONTINUATION(next).setParams(r); CONTINUATION_RUN(CONTINUATION(next)); }); if (r <= 0) { diff --git a/src/msg/async/ProtocolV1.h b/src/msg/async/ProtocolV1.h index cf2370f1a94d..eb0d7f72d353 100644 --- a/src/msg/async/ProtocolV1.h +++ b/src/msg/async/ProtocolV1.h @@ -144,7 +144,7 @@ protected: State state; - void run_continuation(CtPtr continuation); + void run_continuation(CtPtr pcontinuation); CtPtr read(CONTINUATION_PARAM(next, ProtocolV1, char *, int), int len, char *buffer = nullptr); CtPtr write(CONTINUATION_PARAM(next, ProtocolV1, int), bufferlist &bl); diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc index f07a6b8192c6..ed79e9085aee 100644 --- a/src/msg/async/ProtocolV2.cc +++ b/src/msg/async/ProtocolV2.cc @@ -32,8 +32,15 @@ ostream &ProtocolV2::_conn_prefix(std::ostream *_dout) { using namespace ceph::msgr::v2; using CtPtr = Ct *; +using CtRef = Ct &; -void ProtocolV2::run_continuation(CtPtr continuation) { +void ProtocolV2::run_continuation(CtPtr pcontinuation) { + if (pcontinuation) { + run_continuation(*pcontinuation); + } +} + +void ProtocolV2::run_continuation(CtRef continuation) { try { CONTINUATION_RUN(continuation) } catch (const buffer::error &e) { @@ -697,8 +704,8 @@ CtPtr ProtocolV2::read(CONTINUATION_PARAM(next, ProtocolV2, char *, int), buffer = temp_buffer; } ssize_t r = connection->read(len, buffer, - [CONTINUATION(next), this](char *buffer, int r) { - CONTINUATION(next)->setParams(buffer, r); + [&CONTINUATION(next), this](char *buffer, int r) { + CONTINUATION(next).setParams(buffer, r); run_continuation(CONTINUATION(next)); }); if (r <= 0) { @@ -720,7 +727,7 @@ CtPtr ProtocolV2::write(const std::string &desc, CONTINUATION_PARAM(next, ProtocolV2), bufferlist &buffer) { ssize_t r = - connection->write(buffer, [CONTINUATION(next), desc, this](int r) { + connection->write(buffer, [&CONTINUATION(next), desc, this](int r) { if (r < 0) { ldout(cct, 1) << __func__ << " " << desc << " write failed r=" << r << " (" << cpp_strerror(r) << ")" << dendl; @@ -1639,7 +1646,7 @@ CtPtr ProtocolV2::start_client_banner_exchange() { global_seq = messenger->get_global_seq(); - return _banner_exchange(CONTINUATION(post_client_banner_exchange)); + return _banner_exchange(&CONTINUATION(post_client_banner_exchange)); } CtPtr ProtocolV2::post_client_banner_exchange() { @@ -2082,7 +2089,7 @@ CtPtr ProtocolV2::start_server_banner_exchange() { state = BANNER_ACCEPTING; - return _banner_exchange(CONTINUATION(post_server_banner_exchange)); + return _banner_exchange(&CONTINUATION(post_server_banner_exchange)); } CtPtr ProtocolV2::post_server_banner_exchange() { diff --git a/src/msg/async/ProtocolV2.h b/src/msg/async/ProtocolV2.h index 8e166a79c14e..08a16b2cf912 100644 --- a/src/msg/async/ProtocolV2.h +++ b/src/msg/async/ProtocolV2.h @@ -112,7 +112,8 @@ private: bool keepalive; ostream &_conn_prefix(std::ostream *_dout); - void run_continuation(Ct *continuation); + void run_continuation(Ct *pcontinuation); + void run_continuation(Ct &continuation); Ct *read(CONTINUATION_PARAM(next, ProtocolV2, char *, int), int len, char *buffer = nullptr);