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.
pull/18981/head
Soheil Hassas Yeganeh 6 years ago
parent a8644bbc77
commit 2ade64a685
  1. 10
      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<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;
@ -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);
}
}

Loading…
Cancel
Save