From 85a4a93e77b163098e91f41d8e7415181f23d02c Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Fri, 22 Mar 2019 15:29:58 +0100 Subject: [PATCH] Add thread safety annotations for some more PeerConnection members (part 4) Plus all the annotations that were necessary to make things compile again. Bug: webrtc:9987 Change-Id: Ia421e4dc0e1bbc81c3976cc7530d44de934d33bb Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128882 Reviewed-by: Steve Anton Commit-Queue: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#27257} --- pc/peer_connection.h | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 07419bfab7..5fa8da5811 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -246,6 +246,7 @@ class PeerConnection : public PeerConnectionInternal, std::vector> sctp_data_channels() const override { + RTC_DCHECK_RUN_ON(signaling_thread()); return sctp_data_channels_; } @@ -594,17 +595,18 @@ class PeerConnection : public PeerConnectionInternal, absl::optional* audio_index, absl::optional* video_index, absl::optional* data_index, - cricket::MediaSessionOptions* session_options); + cricket::MediaSessionOptions* session_options) + RTC_RUN_ON(signaling_thread()); // Generates the active MediaDescriptionOptions for the local data channel // given the specified MID. cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForActiveData( - const std::string& mid) const; + const std::string& mid) const RTC_RUN_ON(signaling_thread()); // Generates the rejected MediaDescriptionOptions for the local data channel // given the specified MID. cricket::MediaDescriptionOptions GetMediaDescriptionOptionsForRejectedData( - const std::string& mid) const; + const std::string& mid) const RTC_RUN_ON(signaling_thread()); // Returns the MID for the data section associated with either the // RtpDataChannel or SCTP data channel, if it has been set. If no data @@ -672,12 +674,13 @@ class PeerConnection : public PeerConnectionInternal, void OnLocalSenderRemoved(const RtpSenderInfo& sender_info, cricket::MediaType media_type); - void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams); + void UpdateLocalRtpDataChannels(const cricket::StreamParamsVec& streams) + RTC_RUN_ON(signaling_thread()); void UpdateRemoteRtpDataChannels(const cricket::StreamParamsVec& streams) RTC_RUN_ON(signaling_thread()); void UpdateClosingRtpDataChannels( const std::vector& active_channels, - bool is_local_update); + bool is_local_update) RTC_RUN_ON(signaling_thread()); void CreateRemoteRtpDataChannel(const std::string& label, uint32_t remote_ssrc) RTC_RUN_ON(signaling_thread()); @@ -689,12 +692,13 @@ class PeerConnection : public PeerConnectionInternal, const InternalDataChannelInit* config) RTC_RUN_ON(signaling_thread()); // Checks if any data channel has been added. - bool HasDataChannels() const; + bool HasDataChannels() const RTC_RUN_ON(signaling_thread()); - void AllocateSctpSids(rtc::SSLRole role); - void OnSctpDataChannelClosed(DataChannel* channel); + void AllocateSctpSids(rtc::SSLRole role) RTC_RUN_ON(signaling_thread()); + void OnSctpDataChannelClosed(DataChannel* channel) + RTC_RUN_ON(signaling_thread()); - void OnDataChannelDestroyed(); + void OnDataChannelDestroyed() RTC_RUN_ON(signaling_thread()); // Called when a valid data channel OPEN message is received. void OnDataChannelOpenMessage(const std::string& label, const InternalDataChannelInit& config) @@ -749,7 +753,8 @@ class PeerConnection : public PeerConnectionInternal, // Returns the specified SCTP DataChannel in sctp_data_channels_, // or nullptr if not found. - DataChannel* FindDataChannelBySid(int sid) const; + DataChannel* FindDataChannelBySid(int sid) const + RTC_RUN_ON(signaling_thread()); // Called when first configuring the port allocator. struct InitializePortAllocatorResult { @@ -869,7 +874,7 @@ class PeerConnection : public PeerConnectionInternal, void EnableSending(); // Destroys all BaseChannels and destroys the SCTP data channel, if present. - void DestroyAllChannels(); + void DestroyAllChannels() RTC_RUN_ON(signaling_thread()); // Returns the media index for a local ice candidate given the content name. // Returns false if the local session description does not have a media @@ -1010,7 +1015,7 @@ class PeerConnection : public PeerConnectionInternal, transceiver); // Destroys the RTP data channel and/or the SCTP data channel and clears it. - void DestroyDataChannel(); + void DestroyDataChannel() RTC_RUN_ON(signaling_thread()); // Destroys the given ChannelInterface. // The channel cannot be accessed after this method is called. @@ -1134,13 +1139,16 @@ class PeerConnection : public PeerConnectionInternal, std::vector local_video_sender_infos_ RTC_GUARDED_BY(signaling_thread()); - SctpSidAllocator sid_allocator_; + SctpSidAllocator sid_allocator_ RTC_GUARDED_BY(signaling_thread()); // label -> DataChannel - std::map> rtp_data_channels_; - std::vector> sctp_data_channels_; - std::vector> sctp_data_channels_to_free_; + std::map> rtp_data_channels_ + RTC_GUARDED_BY(signaling_thread()); + std::vector> sctp_data_channels_ + RTC_GUARDED_BY(signaling_thread()); + std::vector> sctp_data_channels_to_free_ + RTC_GUARDED_BY(signaling_thread()); - bool remote_peer_supports_msid_ = false; + bool remote_peer_supports_msid_ RTC_GUARDED_BY(signaling_thread()) = false; std::unique_ptr call_; std::unique_ptr stats_; // A pointer is passed to senders_