From d24d13d6eb295f263ffca3def45dd6dc4b053ced Mon Sep 17 00:00:00 2001
From: Craig Tiller <ctiller@google.com>
Date: Wed, 18 Feb 2015 15:35:32 -0800
Subject: [PATCH] Simplify TryPluck

---
 include/grpc++/completion_queue.h  |  2 +-
 src/cpp/common/completion_queue.cc | 20 ++++++++------------
 src/cpp/server/server_context.cc   |  2 +-
 3 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/include/grpc++/completion_queue.h b/include/grpc++/completion_queue.h
index 0bfbd5db7c..0075482d71 100644
--- a/include/grpc++/completion_queue.h
+++ b/include/grpc++/completion_queue.h
@@ -114,7 +114,7 @@ class CompletionQueue {
   bool Pluck(CompletionQueueTag *tag);
 
   // Does a single polling pluck on tag
-  void TryPluck(CompletionQueueTag *tag, bool forever);
+  void TryPluck(CompletionQueueTag *tag);
 
   grpc_completion_queue *cq_;  // owned
 };
diff --git a/src/cpp/common/completion_queue.cc b/src/cpp/common/completion_queue.cc
index 5d186e06cc..414966c1cd 100644
--- a/src/cpp/common/completion_queue.cc
+++ b/src/cpp/common/completion_queue.cc
@@ -77,22 +77,18 @@ bool CompletionQueue::Next(void** tag, bool* ok) {
 bool CompletionQueue::Pluck(CompletionQueueTag* tag) {
   std::unique_ptr<grpc_event, EventDeleter> ev;
 
-  for (;;) {
-    ev.reset(grpc_completion_queue_pluck(cq_, tag, gpr_inf_future));
-    bool ok = ev->data.op_complete == GRPC_OP_OK;
-    void* ignored = tag;
-    if (tag->FinalizeResult(&ignored, &ok)) {
-      GPR_ASSERT(ignored == tag);
-      return ok;
-    }
-  }
+  ev.reset(grpc_completion_queue_pluck(cq_, tag, gpr_inf_future));
+  bool ok = ev->data.op_complete == GRPC_OP_OK;
+  void* ignored = tag;
+  GPR_ASSERT(tag->FinalizeResult(&ignored, &ok));
+  GPR_ASSERT(ignored == tag);
+  return ok;
 }
 
-void CompletionQueue::TryPluck(CompletionQueueTag* tag, bool forever) {
+void CompletionQueue::TryPluck(CompletionQueueTag* tag) {
   std::unique_ptr<grpc_event, EventDeleter> ev;
 
-  ev.reset(grpc_completion_queue_pluck(
-      cq_, tag, forever ? gpr_inf_future : gpr_inf_past));
+  ev.reset(grpc_completion_queue_pluck(cq_, tag, gpr_inf_past));
   if (!ev) return;
   bool ok = ev->data.op_complete == GRPC_OP_OK;
   void* ignored = tag;
diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc
index 92775c9492..1aa18bcac5 100644
--- a/src/cpp/server/server_context.cc
+++ b/src/cpp/server/server_context.cc
@@ -71,7 +71,7 @@ void ServerContext::CompletionOp::Unref() {
 }
 
 bool ServerContext::CompletionOp::CheckCancelled(CompletionQueue* cq) {
-  cq->TryPluck(this, false);
+  cq->TryPluck(this);
   std::lock_guard<std::mutex> g(mu_);
   return finalized_ ? cancelled_ : false;
 }
-- 
GitLab