diff options
Diffstat (limited to 'pw_rpc/client_call.cc')
-rw-r--r-- | pw_rpc/client_call.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/pw_rpc/client_call.cc b/pw_rpc/client_call.cc index d8e57e89a..70ca4344a 100644 --- a/pw_rpc/client_call.cc +++ b/pw_rpc/client_call.cc @@ -23,4 +23,49 @@ void ClientCall::CloseClientCall() { UnregisterAndMarkClosed(); } +void ClientCall::MoveClientCallFrom(ClientCall& other) + PW_EXCLUSIVE_LOCKS_REQUIRED(rpc_lock()) { + WaitUntilReadyForMove(*this, other); + CloseClientCall(); + MoveFrom(other); +} + +void UnaryResponseClientCall::HandleCompleted( + ConstByteSpan response, Status status) PW_NO_LOCK_SAFETY_ANALYSIS { + UnregisterAndMarkClosed(); + + auto on_completed_local = std::move(on_completed_); + CallbackStarted(); + + // The lock is only released when calling into user code. If the callback is + // wrapped, this on_completed is an internal function that expects the lock to + // be held, and releases it before invoking user code. + if (!hold_lock_while_invoking_callback_with_payload()) { + rpc_lock().unlock(); + } + + if (on_completed_local) { + on_completed_local(response, status); + } + + // This mutex lock could be avoided by making callbacks_executing_ atomic. + RpcLockGuard lock; + CallbackFinished(); +} + +void StreamResponseClientCall::HandleCompleted(Status status) { + UnregisterAndMarkClosed(); + auto on_completed_local = std::move(on_completed_); + CallbackStarted(); + rpc_lock().unlock(); + + if (on_completed_local) { + on_completed_local(status); + } + + // This mutex lock could be avoided by making callbacks_executing_ atomic. + RpcLockGuard lock; + CallbackFinished(); +} + } // namespace pw::rpc::internal |