From 0a57193dec25db5e5b44e7a7445fb7b0a55fe571 Mon Sep 17 00:00:00 2001 From: Arjun Roy Date: Thu, 23 May 2019 16:11:23 -0700 Subject: [PATCH 1/2] Replaced gpr_ref with grpc_core::Atomic in call batch struct --- src/core/lib/surface/call.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 254476f47e3..271b3ddd560 100644 --- a/src/core/lib/surface/call.cc +++ b/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 steps_to_complete; gpr_atm batch_error = reinterpret_cast(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, From 7c8d6f63756ff0871cd8e251973375078f151f4f Mon Sep 17 00:00:00 2001 From: Arjun Roy Date: Tue, 28 May 2019 17:13:41 -0700 Subject: [PATCH 2/2] s/uintptr_t/intptr_t as requested --- src/core/lib/surface/call.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 271b3ddd560..e00ac1810de 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -99,7 +99,7 @@ struct batch_control { } completion_data; grpc_closure start_batch; grpc_closure finish_batch; - grpc_core::Atomic steps_to_complete; + grpc_core::Atomic steps_to_complete; gpr_atm batch_error = reinterpret_cast(GRPC_ERROR_NONE); void set_num_steps_to_complete(uintptr_t steps) { steps_to_complete.Store(steps, grpc_core::MemoryOrder::RELEASE);