From b03ab7107c14aef0bce7f57055d7e008c959ad95 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Thu, 14 Feb 2019 11:59:57 +0100 Subject: [PATCH] Add thread safety annotation for PeerConnection::event_log_ Plus all the annotations that are necessary to make things compile again. Bug: webrtc:9987 Change-Id: I68a51bfa3342c6d66d67276d5979144af34692c9 Reviewed-on: https://webrtc-review.googlesource.com/c/123046 Reviewed-by: Steve Anton Commit-Queue: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#26716} --- pc/peer_connection.cc | 7 ++++++- pc/peer_connection.h | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 3d0f664a19..af2e55483c 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -833,6 +833,7 @@ PeerConnection::PeerConnection(PeerConnectionFactory* factory, std::unique_ptr call) : factory_(factory), event_log_(std::move(event_log)), + event_log_ptr_(event_log_.get()), rtcp_cname_(GenerateRtcpCname()), local_streams_(StreamCollection::Create()), remote_streams_(StreamCollection::Create()), @@ -872,6 +873,7 @@ PeerConnection::~PeerConnection() { [this] { port_allocator_.reset(); }); // call_ and event_log_ must be destroyed on the worker thread. worker_thread()->Invoke(RTC_FROM_HERE, [this] { + RTC_DCHECK_RUN_ON(worker_thread()); call_.reset(); // The event log must outlive call (and any other object that uses it). event_log_.reset(); @@ -981,7 +983,7 @@ bool PeerConnection::Initialize( ? *configuration.crypto_options : options.crypto_options; config.transport_observer = this; - config.event_log = event_log_.get(); + config.event_log = event_log_ptr_; #if defined(ENABLE_EXTERNAL_AUTH) config.enable_external_auth = true; #endif @@ -3696,6 +3698,7 @@ void PeerConnection::Close() { port_allocator_.get())); worker_thread()->Invoke(RTC_FROM_HERE, [this] { + RTC_DCHECK_RUN_ON(worker_thread()); call_.reset(); // The event log must outlive call (and any other object that uses it). event_log_.reset(); @@ -5271,6 +5274,7 @@ cricket::ChannelManager* PeerConnection::channel_manager() const { bool PeerConnection::StartRtcEventLog_w( std::unique_ptr output, int64_t output_period_ms) { + RTC_DCHECK_RUN_ON(worker_thread()); if (!event_log_) { return false; } @@ -5278,6 +5282,7 @@ bool PeerConnection::StartRtcEventLog_w( } void PeerConnection::StopRtcEventLog_w() { + RTC_DCHECK_RUN_ON(worker_thread()); if (event_log_) { event_log_->StopLogging(); } diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 321acde834..419c608df5 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -1033,7 +1033,11 @@ class PeerConnection : public PeerConnectionInternal, nullptr; // The EventLog needs to outlive |call_| (and any other object that uses it). - std::unique_ptr event_log_; + std::unique_ptr event_log_ RTC_GUARDED_BY(worker_thread()); + + // Points to the same thing as `event_log_`. Since it's const, we may read the + // pointer (but not touch the object) from any thread. + RtcEventLog* const event_log_ptr_ RTC_PT_GUARDED_BY(worker_thread()); SignalingState signaling_state_ = kStable; IceConnectionState ice_connection_state_ = kIceConnectionNew;