diff --git a/logging/BUILD.gn b/logging/BUILD.gn index b1fb5404e9..7caa7b499f 100644 --- a/logging/BUILD.gn +++ b/logging/BUILD.gn @@ -461,7 +461,6 @@ if (rtc_enable_protobuf) { "../rtc_base:logging", "../rtc_base:macromagic", "../rtc_base:rtc_event", - "../rtc_base:rtc_task_queue", "../rtc_base:safe_conversions", "../rtc_base:safe_minmax", "../rtc_base:timeutils", diff --git a/logging/rtc_event_log/rtc_event_log_impl.cc b/logging/rtc_event_log/rtc_event_log_impl.cc index 77af6966de..419afd330a 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.cc +++ b/logging/rtc_event_log/rtc_event_log_impl.cc @@ -56,10 +56,9 @@ RtcEventLogImpl::RtcEventLogImpl(std::unique_ptr encoder, max_config_events_in_history_(max_config_events_in_history), event_encoder_(std::move(encoder)), last_output_ms_(rtc::TimeMillis()), - task_queue_( - std::make_unique(task_queue_factory->CreateTaskQueue( - "rtc_event_log", - TaskQueueFactory::Priority::NORMAL))) {} + task_queue_(task_queue_factory->CreateTaskQueue( + "rtc_event_log", + TaskQueueFactory::Priority::NORMAL)) {} RtcEventLogImpl::~RtcEventLogImpl() { // If we're logging to the output, this will stop that. Blocking function. @@ -72,10 +71,12 @@ RtcEventLogImpl::~RtcEventLogImpl() { StopLogging(); } - // We want to block on any executing task by invoking ~TaskQueue() before + // Since we are posting tasks bound to `this`, it is critical that the event + // log and its members outlive `task_queue_`. Destruct `task_queue_` first + // to ensure tasks living on the queue can access other members. + // We want to block on any executing task by deleting TaskQueue before // we set unique_ptr's internal pointer to null. - rtc::TaskQueue* tq = task_queue_.get(); - delete tq; + task_queue_.get_deleter()(task_queue_.get()); task_queue_.release(); } diff --git a/logging/rtc_event_log/rtc_event_log_impl.h b/logging/rtc_event_log/rtc_event_log_impl.h index 69ed204da4..2c4ef8d7ed 100644 --- a/logging/rtc_event_log/rtc_event_log_impl.h +++ b/logging/rtc_event_log/rtc_event_log_impl.h @@ -23,10 +23,10 @@ #include "api/rtc_event_log/rtc_event_log.h" #include "api/rtc_event_log_output.h" #include "api/sequence_checker.h" +#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_factory.h" #include "logging/rtc_event_log/encoder/rtc_event_log_encoder.h" #include "rtc_base/system/no_unique_address.h" -#include "rtc_base/task_queue.h" #include "rtc_base/thread_annotations.h" namespace webrtc { @@ -113,11 +113,7 @@ class RtcEventLogImpl final : public RtcEventLog { bool immediately_output_mode_ RTC_GUARDED_BY(mutex_) = false; bool need_schedule_output_ RTC_GUARDED_BY(mutex_) = false; - // Since we are posting tasks bound to `this`, it is critical that the event - // log and its members outlive `task_queue_`. Keep the `task_queue_` - // last to ensure it destructs first, or else tasks living on the queue might - // access other members after they've been torn down. - std::unique_ptr task_queue_; + std::unique_ptr task_queue_; Mutex mutex_; };