Skip to content

Commit

Permalink
[Merge-102] Make metro TQ use the same base::TaskTraits as non-metro TQ.
Browse files Browse the repository at this point in the history
I didn't think the task traits made much of a difference and forgot to
have them align, but when seeing an increase of existing crashes in
https://crbug.com/1319036, I'm wondering if the traits could affect
which thread is chosen during block-invokes.

Whether or not it makes a difference, having the traits match makes
sense since there was no intent to change the behavior of the original
TQ with regards to traits.

(cherry picked from commit 4c01b57)

Bug: 1319786, 1319036
Change-Id: Iaef1ad9860dc89cd2fe59f67448f7f11eaa15934
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3607671
Reviewed-by: Markus Handell <handellm@google.com>
Commit-Queue: Henrik Boström <hbos@chromium.org>
Auto-Submit: Henrik Boström <hbos@chromium.org>
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Commit-Queue: Mirko Bonadei <mbonadei@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#996080}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3610089
Cr-Commit-Position: refs/branch-heads/5005@{#193}
Cr-Branched-From: 5b4d945-refs/heads/main@{#992738}
  • Loading branch information
henbos authored and Chromium LUCI CQ committed Apr 27, 2022
1 parent b96706b commit 9159f49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions third_party/webrtc_overrides/metronome_task_queue_factory.cc
Expand Up @@ -17,6 +17,7 @@
#include "third_party/webrtc/api/task_queue/task_queue_factory.h"
#include "third_party/webrtc_overrides/coalesced_tasks.h"
#include "third_party/webrtc_overrides/metronome_source.h"
#include "third_party/webrtc_overrides/task_queue_factory.h"

namespace blink {

Expand All @@ -25,7 +26,7 @@ const base::Feature kWebRtcMetronomeTaskQueue{

class WebRtcMetronomeTaskQueue : public webrtc::TaskQueueBase {
public:
WebRtcMetronomeTaskQueue();
explicit WebRtcMetronomeTaskQueue(base::TaskTraits traits);

// webrtc::TaskQueueBase implementation.
void Delete() override;
Expand Down Expand Up @@ -56,8 +57,9 @@ class WebRtcMetronomeTaskQueue : public webrtc::TaskQueueBase {
CoalescedTasks coalesced_tasks_;
};

WebRtcMetronomeTaskQueue::WebRtcMetronomeTaskQueue()
: task_runner_(base::ThreadPool::CreateSequencedTaskRunner({})),
WebRtcMetronomeTaskQueue::WebRtcMetronomeTaskQueue(base::TaskTraits traits)
: task_runner_(
base::ThreadPool::CreateSequencedTaskRunner(std::move(traits))),
is_active_(new base::RefCountedData<bool>(true)) {}

void Deactivate(scoped_refptr<base::RefCountedData<bool>> is_active,
Expand Down Expand Up @@ -157,7 +159,7 @@ class WebrtcMetronomeTaskQueueFactory final : public webrtc::TaskQueueFactory {
std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter>
CreateTaskQueue(absl::string_view name, Priority priority) const override {
return std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter>(
new WebRtcMetronomeTaskQueue());
new WebRtcMetronomeTaskQueue(TaskQueuePriority2Traits(priority)));
}
};

Expand Down
4 changes: 2 additions & 2 deletions third_party/webrtc_overrides/task_queue_factory.cc
Expand Up @@ -92,8 +92,6 @@ void WebrtcTaskQueue::PostDelayedTask(std::unique_ptr<webrtc::QueuedTask> task,
base::subtle::DelayPolicy::kPrecise);
}

namespace {

base::TaskTraits TaskQueuePriority2Traits(
webrtc::TaskQueueFactory::Priority priority) {
// The content/renderer/media/webrtc/rtc_video_encoder.* code
Expand All @@ -119,6 +117,8 @@ base::TaskTraits TaskQueuePriority2Traits(
}
}

namespace {

class WebrtcTaskQueueFactory final : public webrtc::TaskQueueFactory {
public:
WebrtcTaskQueueFactory() = default;
Expand Down
7 changes: 7 additions & 0 deletions third_party/webrtc_overrides/task_queue_factory.h
Expand Up @@ -12,6 +12,13 @@
#include "third_party/webrtc/api/task_queue/task_queue_factory.h"
#include "third_party/webrtc/rtc_base/system/rtc_export.h"

namespace blink {

RTC_EXPORT base::TaskTraits TaskQueuePriority2Traits(
webrtc::TaskQueueFactory::Priority priority);

} // namespace blink

// Creates factory for webrtc::TaskQueueBase backed by base::SequencedTaskRunner
// Tested by
// /third_party/blink/renderer/platform/peerconnection/task_queue_factory_test.cc
Expand Down

0 comments on commit 9159f49

Please sign in to comment.