Skip to content
Snippets Groups Projects
Commit d24d13d6 authored by Craig Tiller's avatar Craig Tiller
Browse files

Simplify TryPluck

parent c7625b0e
No related branches found
No related tags found
No related merge requests found
......@@ -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
};
......
......@@ -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;
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment