Skip to content
Snippets Groups Projects
Commit d45a26ed authored by yang-g's avatar yang-g
Browse files

allow null tag

parent 5239ee2b
No related branches found
No related tags found
No related merge requests found
......@@ -128,7 +128,10 @@ class ServerContext {
// Async only. Has to be called before the rpc starts.
// Returns the tag in completion queue when the rpc finishes.
// IsCancelled() can then be called to check whether the rpc was cancelled.
void AsyncNotifyWhenDone(void* tag) { async_notify_when_done_tag_ = tag; }
void AsyncNotifyWhenDone(void* tag) {
has_notify_when_done_tag_ = true;
async_notify_when_done_tag_ = tag;
}
private:
friend class ::grpc::testing::InteropContextInspector;
......@@ -170,6 +173,7 @@ class ServerContext {
void set_call(grpc_call* call);
CompletionOp* completion_op_;
bool has_notify_when_done_tag_;
void* async_notify_when_done_tag_;
gpr_timespec deadline_;
......
......@@ -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_);
}
......
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