JingleThreadWrapper: override TaskQueueBase::Post[Delayed]Task().
This change gets rid of overhead in std::map and locks (visible in http://shortn/_tSjdrNiMky) by overriding and using the internal |task_runner_| Chromium task queue directly, thus avoiding the rtc::Thread ID and MessageHandler system. The result can be seen in http://shortn/_BT1aflWMtm. Fixed: 1223058 Change-Id: I5c93fcd63d27977b47fb2da1127bdfc0618fbf57 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2982659 Commit-Queue: Markus Handell <handellm@google.com> Commit-Queue: Lei Zhang <thestig@chromium.org> Auto-Submit: Markus Handell <handellm@google.com> Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Tommi <tommi@chromium.org> Cr-Commit-Position: refs/heads/master@{#895669}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
b36a6ac6ea
commit
8fd13d1a21
jingle/glue
@ -326,7 +326,23 @@ void JingleThreadWrapper::PostTaskInternal(const rtc::Location& posted_from,
|
||||
}
|
||||
}
|
||||
|
||||
void JingleThreadWrapper::RunTask(int task_id) {
|
||||
void JingleThreadWrapper::PostTask(std::unique_ptr<webrtc::QueuedTask> task) {
|
||||
task_runner_->PostTask(FROM_HERE,
|
||||
base::BindOnce(&JingleThreadWrapper::RunTaskQueueTask,
|
||||
weak_ptr_, std::move(task)));
|
||||
}
|
||||
|
||||
void JingleThreadWrapper::PostDelayedTask(
|
||||
std::unique_ptr<webrtc::QueuedTask> task,
|
||||
uint32_t milliseconds) {
|
||||
task_runner_->PostDelayedTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&JingleThreadWrapper::RunTaskQueueTask, weak_ptr_,
|
||||
std::move(task)),
|
||||
base::TimeDelta::FromMilliseconds(milliseconds));
|
||||
}
|
||||
|
||||
absl::optional<base::TimeTicks> JingleThreadWrapper::PrepareRunTask() {
|
||||
if (!latency_sampler_ && task_latency_callback_) {
|
||||
latency_sampler_ = std::make_unique<PostTaskLatencySampler>(
|
||||
task_runner_, std::move(task_latency_callback_));
|
||||
@ -336,10 +352,35 @@ void JingleThreadWrapper::RunTask(int task_id) {
|
||||
latency_sampler_->ShouldSampleNextTaskDuration()) {
|
||||
task_start_timestamp = base::TimeTicks::Now();
|
||||
}
|
||||
return task_start_timestamp;
|
||||
}
|
||||
|
||||
void JingleThreadWrapper::RunTaskQueueTask(
|
||||
std::unique_ptr<webrtc::QueuedTask> task) {
|
||||
absl::optional<base::TimeTicks> task_start_timestamp = PrepareRunTask();
|
||||
|
||||
// Follow QueuedTask::Run() semantics: delete if it returns true, release
|
||||
// otherwise.
|
||||
if (task->Run())
|
||||
task.reset();
|
||||
else
|
||||
task.release();
|
||||
|
||||
FinalizeRunTask(std::move(task_start_timestamp));
|
||||
}
|
||||
|
||||
void JingleThreadWrapper::RunTask(int task_id) {
|
||||
absl::optional<base::TimeTicks> task_start_timestamp = PrepareRunTask();
|
||||
|
||||
RunTaskInternal(task_id);
|
||||
if (task_start_timestamp.has_value()) {
|
||||
|
||||
FinalizeRunTask(std::move(task_start_timestamp));
|
||||
}
|
||||
|
||||
void JingleThreadWrapper::FinalizeRunTask(
|
||||
absl::optional<base::TimeTicks> task_start_timestamp) {
|
||||
if (task_start_timestamp.has_value())
|
||||
task_duration_callback_.Run(base::TimeTicks::Now() - *task_start_timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
void JingleThreadWrapper::RunTaskInternal(int task_id) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "base/synchronization/waitable_event.h"
|
||||
#include "base/task/current_thread.h"
|
||||
#include "base/time/time.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/webrtc/rtc_base/thread.h"
|
||||
|
||||
namespace jingle_glue {
|
||||
@ -141,6 +142,22 @@ class JingleThreadWrapper : public base::CurrentThread::DestructionObserver,
|
||||
void RunTaskInternal(int task_id);
|
||||
void ProcessPendingSends();
|
||||
|
||||
// TaskQueueBase overrides.
|
||||
void PostTask(std::unique_ptr<webrtc::QueuedTask> task) override;
|
||||
void PostDelayedTask(std::unique_ptr<webrtc::QueuedTask> task,
|
||||
uint32_t milliseconds) override;
|
||||
|
||||
// Executes WebRTC queued tasks from TaskQueueBase overrides on
|
||||
// |task_runner_|.
|
||||
void RunTaskQueueTask(std::unique_ptr<webrtc::QueuedTask> task);
|
||||
|
||||
// Called before a task runs, returns an opaque optional timestamp which
|
||||
// should be passed into FinalizeRunTask.
|
||||
absl::optional<base::TimeTicks> PrepareRunTask();
|
||||
// Called after a task has run. Move the return value of PrepareRunTask as
|
||||
// |task_start_timestamp|.
|
||||
void FinalizeRunTask(absl::optional<base::TimeTicks> task_start_timestamp);
|
||||
|
||||
// Task runner used to execute messages posted on this thread.
|
||||
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
||||
|
||||
|
Reference in New Issue
Block a user