aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Vijay Pai <vpai@google.com>2018-11-06 11:49:17 -0800
committerGravatar Vijay Pai <vpai@google.com>2018-11-06 11:49:17 -0800
commit1e850944e91a30a4985a90d394c82f9e8626e1a0 (patch)
tree7e8af9fe96cc5fded39f29fe6273f25be2a65387 /include
parent526d2e6004636156dbd9f2c56b51f428d3e5ab14 (diff)
Release the CallbackWithSuccessTag from a server context completionop
Diffstat (limited to 'include')
-rw-r--r--include/grpcpp/impl/codegen/callback_common.h24
1 files changed, 14 insertions, 10 deletions
diff --git a/include/grpcpp/impl/codegen/callback_common.h b/include/grpcpp/impl/codegen/callback_common.h
index 11f54295cd..51367cf550 100644
--- a/include/grpcpp/impl/codegen/callback_common.h
+++ b/include/grpcpp/impl/codegen/callback_common.h
@@ -138,16 +138,11 @@ class CallbackWithSuccessTag
CallbackWithSuccessTag(const CallbackWithSuccessTag&) = delete;
CallbackWithSuccessTag& operator=(const CallbackWithSuccessTag&) = delete;
- ~CallbackWithSuccessTag() {
- if (call_ != nullptr) {
- func_ = nullptr;
- g_core_codegen_interface->grpc_call_unref(call_);
- }
- }
+ ~CallbackWithSuccessTag() { Clear(); }
- // Set can only be called on a default-constructed tag, and it can only
- // be called exactly once. It should never be called on a tag that was
- // constructed with arguments or on a tag that has been Set before
+ // Set can only be called on a default-constructed or Clear'ed tag.
+ // It should never be called on a tag that was constructed with arguments
+ // or on a tag that has been Set before unless the tag has been cleared.
void Set(grpc_call* call, std::function<void(bool)> f,
CompletionQueueTag* ops) {
call_ = call;
@@ -157,6 +152,15 @@ class CallbackWithSuccessTag
functor_run = &CallbackWithSuccessTag::StaticRun;
}
+ void Clear() {
+ if (call_ != nullptr) {
+ func_ = nullptr;
+ grpc_call* call = call_;
+ call_ = nullptr;
+ g_core_codegen_interface->grpc_call_unref(call);
+ }
+ }
+
CompletionQueueTag* ops() { return ops_; }
// force_run can not be performed on a tag if operations using this tag
@@ -164,7 +168,7 @@ class CallbackWithSuccessTag
// that are detected before the operations are internally processed.
void force_run(bool ok) { Run(ok); }
- /// check if this tag has ever been set
+ /// check if this tag is currently set
operator bool() const { return call_ != nullptr; }
private: