Merge pull request #19129 from arjunroy/call_atomic_batchref

Replaced gpr_ref with grpc_core::Atomic in call batch struct
pull/19197/head
Arjun Roy 6 years ago committed by GitHub
commit 0dc4c8ab1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/core/lib/surface/call.cc

@ -74,7 +74,7 @@
#define ESTIMATED_MDELEM_COUNT 16
struct batch_control {
batch_control() { gpr_ref_init(&steps_to_complete, 0); }
batch_control() = default;
grpc_call* call = nullptr;
grpc_transport_stream_op_batch op;
@ -99,8 +99,14 @@ struct batch_control {
} completion_data;
grpc_closure start_batch;
grpc_closure finish_batch;
gpr_refcount steps_to_complete;
grpc_core::Atomic<intptr_t> steps_to_complete;
gpr_atm batch_error = reinterpret_cast<gpr_atm>(GRPC_ERROR_NONE);
void set_num_steps_to_complete(uintptr_t steps) {
steps_to_complete.Store(steps, grpc_core::MemoryOrder::RELEASE);
}
bool completed_batch_step() {
return steps_to_complete.FetchSub(1, grpc_core::MemoryOrder::ACQ_REL) == 1;
}
};
struct parent_call {
@ -1225,7 +1231,7 @@ static void post_batch_completion(batch_control* bctl) {
}
static void finish_batch_step(batch_control* bctl) {
if (GPR_UNLIKELY(gpr_unref(&bctl->steps_to_complete))) {
if (GPR_UNLIKELY(bctl->completed_batch_step())) {
post_batch_completion(bctl);
}
}
@ -1866,7 +1872,7 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops,
if (!is_notify_tag_closure) {
GPR_ASSERT(grpc_cq_begin_op(call->cq, notify_tag));
}
gpr_ref_init(&bctl->steps_to_complete, (has_send_ops ? 1 : 0) + num_recv_ops);
bctl->set_num_steps_to_complete((has_send_ops ? 1 : 0) + num_recv_ops);
if (has_send_ops) {
GRPC_CLOSURE_INIT(&bctl->finish_batch, finish_batch, bctl,

Loading…
Cancel
Save