Commit ef055860 authored by Yuta Kitamura's avatar Yuta Kitamura Committed by Commit Bot

Use ThreadScheduler::Current() in platform/.

This CL replaces the occurrences of "Platform::Current()
->CurrentThread()->Scheduler()" with "ThreadScheduler::Current()"
which has the same meaning.

Also, this CL simplifies the code that assumes Platform::CurrentThread()
or Thread::Scheduler() can return null, which is no longer true.

Bug: 826203
Change-Id: I0a59ef17be978d3a4d8b229dc19069aeb0a4c2f1
Reviewed-on: https://chromium-review.googlesource.com/c/1314084Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Yuta Kitamura <yutak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605275}
parent d81275b1
......@@ -98,16 +98,10 @@ void ScriptWrappableMarkingVisitor::PerformCleanup() {
}
void ScriptWrappableMarkingVisitor::ScheduleIdleLazyCleanup() {
Thread* const thread = Platform::Current()->CurrentThread();
// Thread might already be gone, or some threads (e.g. PPAPI) don't have a
// scheduler.
if (!thread || !thread->Scheduler())
return;
if (idle_cleanup_task_scheduled_)
return;
Platform::Current()->CurrentThread()->Scheduler()->PostIdleTask(
ThreadScheduler::Current()->PostIdleTask(
FROM_HERE, WTF::Bind(&ScriptWrappableMarkingVisitor::PerformLazyCleanup,
WTF::Unretained(this)));
idle_cleanup_task_scheduled_ = true;
......
......@@ -62,10 +62,8 @@ void BeginFrameProvider::CreateCompositorFrameSinkIfNeeded() {
Platform::Current()->GetInterfaceProvider()->GetInterface(
mojo::MakeRequest(&provider));
scoped_refptr<base::SingleThreadTaskRunner> task_runner;
auto* scheduler = blink::Platform::Current()->CurrentThread()->Scheduler();
if (scheduler)
task_runner = scheduler->CompositorTaskRunner();
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
ThreadScheduler::Current()->CompositorTaskRunner();
mojom::blink::EmbeddedFrameSinkClientPtr efs_client;
efs_binding_.Bind(mojo::MakeRequest(&efs_client), task_runner);
......
......@@ -415,7 +415,7 @@ void Canvas2DLayerBridge::SetIsHidden(bool hidden) {
FROM_HERE, WTF::Bind(&HibernateWrapperForTesting,
weak_ptr_factory_.GetWeakPtr()));
} else {
Platform::Current()->CurrentThread()->Scheduler()->PostIdleTask(
ThreadScheduler::Current()->PostIdleTask(
FROM_HERE,
WTF::Bind(&HibernateWrapper, weak_ptr_factory_.GetWeakPtr()));
}
......
......@@ -221,15 +221,7 @@ void ThreadState::AttachMainThread() {
thread_specific_ = new WTF::ThreadSpecific<ThreadState*>();
new (main_thread_state_storage_) ThreadState();
// PpapiThread doesn't set the current thread.
Thread* current_thread = Platform::Current()->CurrentThread();
if (current_thread) {
ThreadScheduler* scheduler = current_thread->Scheduler();
// Some binaries do not have a scheduler (e.g.
// v8_context_snapshot_generator)
if (scheduler)
scheduler->AddRAILModeObserver(MainThreadState());
}
ThreadScheduler::Current()->AddRAILModeObserver(MainThreadState());
}
void ThreadState::AttachCurrentThread() {
......@@ -693,7 +685,6 @@ ThreadState* ThreadState::FromObject(const void* object) {
void ThreadState::PerformIdleGC(TimeTicks deadline) {
DCHECK(CheckThread());
DCHECK(Platform::Current()->CurrentThread()->Scheduler());
if (GetGCState() != kIdleGCScheduled)
return;
......@@ -707,10 +698,7 @@ void ThreadState::PerformIdleGC(TimeTicks deadline) {
TimeDelta estimated_marking_time =
heap_->stats_collector()->estimated_marking_time();
if ((deadline - CurrentTimeTicks()) <= estimated_marking_time &&
!Platform::Current()
->CurrentThread()
->Scheduler()
->CanExceedIdleDeadlineIfRequired()) {
!ThreadScheduler::Current()->CanExceedIdleDeadlineIfRequired()) {
// If marking is estimated to take longer than the deadline and we can't
// exceed the deadline, then reschedule for the next idle period.
RescheduleIdleGC();
......@@ -773,18 +761,13 @@ void ThreadState::ScheduleIncrementalMarkingFinalize() {
}
void ThreadState::ScheduleIdleGC() {
// Some threads (e.g. PPAPI thread) don't have a scheduler.
// Also some tests can call Platform::SetCurrentPlatformForTesting() at any
// time, so we need to check if it exists.
if (!Platform::Current()->CurrentThread()->Scheduler())
return;
// Idle GC has the lowest priority so do not schedule if a GC is already
// scheduled or if marking is in progress.
if (GetGCState() != kNoGCScheduled)
return;
CompleteSweep();
SetGCState(kIdleGCScheduled);
Platform::Current()->CurrentThread()->Scheduler()->PostNonNestableIdleTask(
ThreadScheduler::Current()->PostNonNestableIdleTask(
FROM_HERE, WTF::Bind(&ThreadState::PerformIdleGC, WTF::Unretained(this)));
}
......@@ -795,11 +778,7 @@ void ThreadState::RescheduleIdleGC() {
}
void ThreadState::ScheduleIdleLazySweep() {
// Some threads (e.g. PPAPI thread) don't have a scheduler.
if (!Platform::Current()->CurrentThread()->Scheduler())
return;
Platform::Current()->CurrentThread()->Scheduler()->PostIdleTask(
ThreadScheduler::Current()->PostIdleTask(
FROM_HERE,
WTF::Bind(&ThreadState::PerformIdleLazySweep, WTF::Unretained(this)));
}
......
......@@ -28,9 +28,6 @@ class PLATFORM_EXPORT ThreadScheduler {
scheduler::WebThreadScheduler::RendererPauseHandle;
// Return the current thread's ThreadScheduler.
//
// TODO(yutak): Replace all the "Platform::Current()->CurrentThread()
// ->Scheduler()" calls in Blink with this.
static ThreadScheduler* Current();
virtual ~ThreadScheduler() = default;
......
......@@ -163,10 +163,8 @@ bool TimerBase::Comparator::operator()(const TimerBase* a,
// static
TimeTicks TimerBase::TimerCurrentTimeTicks() const {
return WTF::TimeTicks(Platform::Current()
->CurrentThread()
->Scheduler()
->MonotonicallyIncreasingVirtualTime());
return WTF::TimeTicks(
ThreadScheduler::Current()->MonotonicallyIncreasingVirtualTime());
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment