You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2017/05/19 21:00:25 UTC

[3/3] kudu git commit: consensus_peers: avoid C++14-ism (lambda capture with initializer)

consensus_peers: avoid C++14-ism (lambda capture with initializer)

When compiling with -std=c++11 as we do, warnings are emitted for
initializers inside lambda capture expressions [1]. It appears that all of
our C++11 compliant compilers accept this, and it's a little better for
performance (by doing away with an addref/deref pair), but man are those
warnings ugly.

1. http://en.cppreference.com/w/cpp/language/lambda for details.

Change-Id: I7c963882ad753ca405ccef8547584776d5cf3cf6
Reviewed-on: http://gerrit.cloudera.org:8080/6930
Reviewed-by: Todd Lipcon <to...@apache.org>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/b46a2a22
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/b46a2a22
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/b46a2a22

Branch: refs/heads/master
Commit: b46a2a22dcdcc290d51a8da5810a78272b52f716
Parents: b21911a
Author: Adar Dembo <ad...@cloudera.com>
Authored: Fri May 19 12:40:42 2017 -0700
Committer: Adar Dembo <ad...@cloudera.com>
Committed: Fri May 19 20:59:59 2017 +0000

----------------------------------------------------------------------
 src/kudu/consensus/consensus_peers.cc | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/b46a2a22/src/kudu/consensus/consensus_peers.cc
----------------------------------------------------------------------
diff --git a/src/kudu/consensus/consensus_peers.cc b/src/kudu/consensus/consensus_peers.cc
index 26bbe06..8a13916 100644
--- a/src/kudu/consensus/consensus_peers.cc
+++ b/src/kudu/consensus/consensus_peers.cc
@@ -132,8 +132,10 @@ Status Peer::SignalRequest(bool even_if_queue_empty) {
   if (PREDICT_FALSE(closed_)) {
     return Status::IllegalState("Peer was closed.");
   }
-
-  RETURN_NOT_OK(thread_pool_->SubmitFunc([=, s_this = shared_from_this()]() {
+  // Capture a shared_ptr reference into the submitted functor so that we're
+  // guaranteed that this object outlives the functor.
+  shared_ptr<Peer> s_this = shared_from_this();
+  RETURN_NOT_OK(thread_pool_->SubmitFunc([even_if_queue_empty, s_this]() {
         s_this->SendNextRequest(even_if_queue_empty);
       }));
   return Status::OK();
@@ -195,8 +197,9 @@ void Peer::SendNextRequest(bool even_if_queue_empty) {
       l.unlock();
       // Capture a shared_ptr reference into the RPC callback so that we're guaranteed
       // that this object outlives the RPC.
+      shared_ptr<Peer> s_this = shared_from_this();
       proxy_->StartTabletCopy(&tc_request_, &tc_response_, &controller_,
-                              [s_this = shared_from_this()]() {
+                              [s_this]() {
                                 s_this->ProcessTabletCopyResponse();
                               });
     } else {
@@ -234,8 +237,9 @@ void Peer::SendNextRequest(bool even_if_queue_empty) {
   l.unlock();
   // Capture a shared_ptr reference into the RPC callback so that we're guaranteed
   // that this object outlives the RPC.
+  shared_ptr<Peer> s_this = shared_from_this();
   proxy_->UpdateAsync(&request_, &response_, &controller_,
-                      [s_this = shared_from_this()]() {
+                      [s_this]() {
                         s_this->ProcessResponse();
                       });
 }
@@ -281,7 +285,11 @@ void Peer::ProcessResponse() {
   // the WAL) and SendNextRequest() may do the same thing. So we run the rest
   // of the response handling logic on our thread pool and not on the reactor
   // thread.
-  Status s = thread_pool_->SubmitFunc([s_this = shared_from_this()]() {
+  //
+  // Capture a shared_ptr reference into the submitted functor so that we're
+  // guaranteed that this object outlives the functor.
+  shared_ptr<Peer> s_this = shared_from_this();
+  Status s = thread_pool_->SubmitFunc([s_this]() {
       s_this->DoProcessResponse();
     });
   if (PREDICT_FALSE(!s.ok())) {