From 2ade64a685094546943daafdec22028f4117ab17 Mon Sep 17 00:00:00 2001 From: Soheil Hassas Yeganeh Date: Tue, 7 May 2019 15:53:22 -0400 Subject: [PATCH] Use grpc_core::RefCount for grpc_call and mark Unref path unlikely. Unfortunately, we cannot use RefCount for `batch`, unless we support reset API. So, for now, let's mark its unref path as unlikely. --- src/core/lib/surface/call.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index bd140021c9678..a826a619542fc 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -39,6 +39,7 @@ #include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/arena.h" #include "src/core/lib/gprpp/manual_constructor.h" +#include "src/core/lib/gprpp/ref_counted.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" @@ -130,7 +131,6 @@ struct grpc_call { channel(args.channel), is_client(args.server_transport_data == nullptr), stream_op_payload(context) { - gpr_ref_init(&ext_ref, 1); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { metadata_batch[i][j].deadline = GRPC_MILLIS_INF_FUTURE; @@ -142,7 +142,7 @@ struct grpc_call { gpr_free(static_cast(const_cast(final_info.error_string))); } - gpr_refcount ext_ref; + grpc_core::RefCount ext_ref; grpc_core::Arena* arena; grpc_core::CallCombiner call_combiner; grpc_completion_queue* cq; @@ -553,10 +553,10 @@ static void destroy_call(void* call, grpc_error* error) { grpc_schedule_on_exec_ctx)); } -void grpc_call_ref(grpc_call* c) { gpr_ref(&c->ext_ref); } +void grpc_call_ref(grpc_call* c) { c->ext_ref.Ref(); } void grpc_call_unref(grpc_call* c) { - if (!gpr_unref(&c->ext_ref)) return; + if (GPR_LIKELY(!c->ext_ref.Unref())) return; GPR_TIMER_SCOPE("grpc_call_unref", 0); @@ -1225,7 +1225,7 @@ static void post_batch_completion(batch_control* bctl) { } static void finish_batch_step(batch_control* bctl) { - if (gpr_unref(&bctl->steps_to_complete)) { + if (GPR_UNLIKELY(gpr_unref(&bctl->steps_to_complete))) { post_batch_completion(bctl); } }