Skip to content

Commit

Permalink
Use grpc_core::RefCount for grpc_call and mark Unref path unlikely.
Browse files Browse the repository at this point in the history
Unfortunately, we cannot use RefCount for `batch`, unless we support
reset API. So, for now, let's mark its unref path as unlikely.
  • Loading branch information
soheilhy committed May 8, 2019
1 parent a8644bb commit 2ade64a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/lib/surface/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -142,7 +142,7 @@ struct grpc_call {
gpr_free(static_cast<void*>(const_cast<char*>(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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 2ade64a

Please sign in to comment.