From 7a651c6e5866fb74f8efbe6f1d93d79b5f34f9dd Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Tue, 2 Apr 2019 13:00:46 +0200 Subject: [PATCH] Add thread safety annotations for some more PeerConnection members (part 10) Plus all the annotations that were necessary to make things compile again. Bug: webrtc:9987 Change-Id: I2b08c7db10dda7b18ad4ba036125f2a56ebf80a0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130478 Reviewed-by: Steve Anton Commit-Queue: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#27419} --- pc/peer_connection.cc | 10 +++++----- pc/peer_connection.h | 14 +++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index a7fc8db6b3..2a4cdd0ea1 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -6366,7 +6366,7 @@ bool PeerConnection::CreateSctpTransport_n(const std::string& mid) { } void PeerConnection::DestroySctpTransport_n() { - RTC_DCHECK(network_thread()->IsCurrent()); + RTC_DCHECK_RUN_ON(network_thread()); sctp_transport_->Clear(); sctp_transport_ = nullptr; sctp_mid_.reset(); @@ -6374,8 +6374,8 @@ void PeerConnection::DestroySctpTransport_n() { } void PeerConnection::OnSctpTransportReadyToSendData_n() { + RTC_DCHECK_RUN_ON(network_thread()); RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); - RTC_DCHECK(network_thread()->IsCurrent()); // Note: Cannot use rtc::Bind here because it will grab a reference to // PeerConnection and potentially cause PeerConnection to live longer than // expected. It is safe not to grab a reference since the sctp_invoker_ will @@ -6395,8 +6395,8 @@ void PeerConnection::OnSctpTransportReadyToSendData_s(bool ready) { void PeerConnection::OnSctpTransportDataReceived_n( const cricket::ReceiveDataParams& params, const rtc::CopyOnWriteBuffer& payload) { + RTC_DCHECK_RUN_ON(network_thread()); RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); - RTC_DCHECK(network_thread()->IsCurrent()); // Note: Cannot use rtc::Bind here because it will grab a reference to // PeerConnection and potentially cause PeerConnection to live longer than // expected. It is safe not to grab a reference since the sctp_invoker_ will @@ -6418,8 +6418,8 @@ void PeerConnection::OnSctpTransportDataReceived_s( } void PeerConnection::OnSctpClosingProcedureStartedRemotely_n(int sid) { + RTC_DCHECK_RUN_ON(network_thread()); RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); - RTC_DCHECK(network_thread()->IsCurrent()); sctp_invoker_->AsyncInvoke( RTC_FROM_HERE, signaling_thread(), rtc::Bind(&sigslot::signal1::operator(), @@ -6427,8 +6427,8 @@ void PeerConnection::OnSctpClosingProcedureStartedRemotely_n(int sid) { } void PeerConnection::OnSctpClosingProcedureComplete_n(int sid) { + RTC_DCHECK_RUN_ON(network_thread()); RTC_DCHECK(data_channel_type_ == cricket::DCT_SCTP); - RTC_DCHECK(network_thread()->IsCurrent()); sctp_invoker_->AsyncInvoke( RTC_FROM_HERE, signaling_thread(), rtc::Bind(&sigslot::signal1::operator(), diff --git a/pc/peer_connection.h b/pc/peer_connection.h index b584ebeeac..2b28f3f5d8 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -1236,13 +1236,17 @@ class PeerConnection : public PeerConnectionInternal, // TODO(deadbeef): Use a proxy object to ensure that method calls/signals // are marshalled to the right thread. Could almost use proxy.h for this, // but it doesn't have a mechanism for marshalling sigslot::signals - std::unique_ptr sctp_invoker_; - sigslot::signal1 SignalSctpReadyToSendData; + std::unique_ptr sctp_invoker_ + RTC_GUARDED_BY(network_thread()); + sigslot::signal1 SignalSctpReadyToSendData + RTC_GUARDED_BY(signaling_thread()); sigslot::signal2 - SignalSctpDataReceived; - sigslot::signal1 SignalSctpClosingProcedureStartedRemotely; - sigslot::signal1 SignalSctpClosingProcedureComplete; + SignalSctpDataReceived RTC_GUARDED_BY(signaling_thread()); + sigslot::signal1 SignalSctpClosingProcedureStartedRemotely + RTC_GUARDED_BY(signaling_thread()); + sigslot::signal1 SignalSctpClosingProcedureComplete + RTC_GUARDED_BY(signaling_thread()); // Whether this peer is the caller. Set when the local description is applied. absl::optional is_caller_ RTC_GUARDED_BY(signaling_thread());