diff options
author | 2015-08-04 16:36:22 -0700 | |
---|---|---|
committer | 2015-08-04 16:36:22 -0700 | |
commit | d45a26ed06dfeafa41f49d17fe42a2f637ad6742 (patch) | |
tree | 9ada01d183a10b794969ee3ca27df69779cbf587 /src | |
parent | 5239ee2bd0a035ad7ac94b259b318677869126ad (diff) |
allow null tag
Diffstat (limited to 'src')
-rw-r--r-- | src/cpp/server/server_context.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 0d09519b28..04373397f9 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -50,18 +50,22 @@ namespace grpc { class ServerContext::CompletionOp GRPC_FINAL : public CallOpSetInterface { public: // initial refs: one in the server context, one in the cq - CompletionOp() : refs_(2), finalized_(false), cancelled_(0) {} + CompletionOp() : has_tag_(false), tag_(nullptr), refs_(2), finalized_(false), cancelled_(0) {} void FillOps(grpc_op* ops, size_t* nops) GRPC_OVERRIDE; bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE; bool CheckCancelled(CompletionQueue* cq); - void set_tag(void* tag) { tag_ = tag; } + void set_tag(void* tag) { + has_tag_ = true; + tag_ = tag; + } void Unref(); private: + bool has_tag_; void* tag_; grpc::mutex mu_; int refs_; @@ -94,7 +98,7 @@ bool ServerContext::CompletionOp::FinalizeResult(void** tag, bool* status) { grpc::unique_lock<grpc::mutex> lock(mu_); finalized_ = true; bool ret = false; - if (tag_) { + if (has_tag_) { *tag = tag_; ret = true; } @@ -110,6 +114,7 @@ bool ServerContext::CompletionOp::FinalizeResult(void** tag, bool* status) { ServerContext::ServerContext() : completion_op_(nullptr), + has_notify_when_done_tag_(false), async_notify_when_done_tag_(nullptr), call_(nullptr), cq_(nullptr), @@ -118,6 +123,7 @@ ServerContext::ServerContext() ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, size_t metadata_count) : completion_op_(nullptr), + has_notify_when_done_tag_(false), async_notify_when_done_tag_(nullptr), deadline_(deadline), call_(nullptr), @@ -143,7 +149,9 @@ ServerContext::~ServerContext() { void ServerContext::BeginCompletionOp(Call* call) { GPR_ASSERT(!completion_op_); completion_op_ = new CompletionOp(); - completion_op_->set_tag(async_notify_when_done_tag_); + if (has_notify_when_done_tag_) { + completion_op_->set_tag(async_notify_when_done_tag_); + } call->PerformOps(completion_op_); } |