]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async: avoid extra pointers in continuation definitions.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 8 Mar 2019 00:31:10 +0000 (01:31 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Sun, 10 Mar 2019 00:11:59 +0000 (01:11 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/msg/async/Protocol.h
src/msg/async/ProtocolV1.cc
src/msg/async/ProtocolV1.h
src/msg/async/ProtocolV2.cc
src/msg/async/ProtocolV2.h

index e971448532e127947039b82800031ec732d44045..b4a29814c5383dca551cb93a21a0bb70729e2531 100644 (file)
@@ -47,21 +47,19 @@ public:
 };
 
 #define CONTINUATION_DECL(C, F, ...)                    \
-  std::unique_ptr<CtFun<C, ##__VA_ARGS__>> F##_cont_ =  \
-      std::make_unique<CtFun<C, ##__VA_ARGS__>>(&C::F); \
-  CtFun<C, ##__VA_ARGS__> *F##_cont = F##_cont_.get()
+  CtFun<C, ##__VA_ARGS__> F##_cont { (&C::F) };
 
-#define CONTINUATION_PARAM(V, C, ...) CtFun<C, ##__VA_ARGS__> *V##_cont
+#define CONTINUATION_PARAM(V, C, ...) CtFun<C, ##__VA_ARGS__> &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<std::remove_reference<decltype(*this)>::type> *_cont = CT; \
-    while (_cont) {                                               \
+    Ct<std::remove_reference<decltype(*this)>::type> *_cont = &CT;\
+    do {                                                          \
       _cont = _cont->call(this);                                  \
-    }                                                             \
+    } while (_cont);                                              \
   }
 
 #define READ_HANDLER_CONTINUATION_DECL(C, F) \
index 3857ed5c14d0838b3808427c63fd53fcb71aa6a1..e7aeb4f197a39624218320994ccfca5267305acf 100644 (file)
@@ -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) {
index cf2370f1a94d00a741549ff33b74c1020939e61f..eb0d7f72d353ab25f3e3143fa2490bd960476e01 100644 (file)
@@ -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);
index f07a6b8192c6b5876e55c94ab1bda32ffe889a9a..ed79e9085aeecfe96e1776f989c20fff1bb9a062 100644 (file)
@@ -32,8 +32,15 @@ ostream &ProtocolV2::_conn_prefix(std::ostream *_dout) {
 using namespace ceph::msgr::v2;
 
 using CtPtr = Ct<ProtocolV2> *;
+using CtRef = Ct<ProtocolV2> &;
 
-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() {
index 8e166a79c14e8da1638d89ab06843e29e9b9ef22..08a16b2cf912b43712d68c6d7f0c5ed07dc3eec2 100644 (file)
@@ -112,7 +112,8 @@ private:
   bool keepalive;
 
   ostream &_conn_prefix(std::ostream *_dout);
-  void run_continuation(Ct<ProtocolV2> *continuation);
+  void run_continuation(Ct<ProtocolV2> *pcontinuation);
+  void run_continuation(Ct<ProtocolV2> &continuation);
 
   Ct<ProtocolV2> *read(CONTINUATION_PARAM(next, ProtocolV2, char *, int),
                        int len, char *buffer = nullptr);