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;