From bedf57fe8c323c2e26a2ad64e29521a353343a6b Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Fri, 5 Feb 2016 16:45:54 -0800 Subject: [PATCH] Ref the collection only when it will be used (and later finalized) --- include/grpc++/impl/codegen/async_unary_call.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/grpc++/impl/codegen/async_unary_call.h b/include/grpc++/impl/codegen/async_unary_call.h index f78ba891e87..f3c75dc3b1d 100644 --- a/include/grpc++/impl/codegen/async_unary_call.h +++ b/include/grpc++/impl/codegen/async_unary_call.h @@ -65,7 +65,7 @@ class ClientAsyncResponseReader GRPC_FINAL : context_(context), call_(channel->CreateCall(method, context, cq)), collection_(new CallOpSetCollection) { - collection_->SetCollection(); + collection_->init_buf_.SetCollection(collection_); collection_->init_buf_.SendInitialMetadata(context->send_initial_metadata_); // TODO(ctiller): don't assert GPR_ASSERT(collection_->init_buf_.SendMessage(request).ok()); @@ -76,12 +76,14 @@ class ClientAsyncResponseReader GRPC_FINAL void ReadInitialMetadata(void* tag) { GPR_ASSERT(!context_->initial_metadata_received_); + collection_->meta_buf_.SetCollection(collection_); collection_->meta_buf_.set_output_tag(tag); collection_->meta_buf_.RecvInitialMetadata(context_); call_.PerformOps(&collection_->meta_buf_); } void Finish(R* msg, Status* status, void* tag) { + collection_->finish_buf_.SetCollection(collection_); collection_->finish_buf_.set_output_tag(tag); if (!context_->initial_metadata_received_) { collection_->finish_buf_.RecvInitialMetadata(context_); @@ -97,11 +99,6 @@ class ClientAsyncResponseReader GRPC_FINAL class CallOpSetCollection : public CallOpSetCollectionInterface { public: - void SetCollection() { - init_buf_.SetCollection(shared_from_this()); - meta_buf_.SetCollection(shared_from_this()); - finish_buf_.SetCollection(shared_from_this()); - } SneakyCallOpSet init_buf_; CallOpSet meta_buf_;