Files
engine/fml/message_loop.cc
T
Kaushik Iska 971a639151 Allow for dynamic thread merging on IOS for embedded view mutations (#9819)
After pre-roll we know if there have been any mutations made to the IOS embedded UIViews. If there are any mutations and the thread configuration is such chat the mutations will be committed on an illegal thread (GPU thread), we merge the threads and keep them merged until the lease expires. The lease is currently set to expire after 10 frames of no mutations. If there are any mutations in the interim we extend the lease.

TaskRunnerMerger will ultimately be responsible for enforcing the correct thread configurations.

This configuration will be inactive even after this change since still use the same thread when we create the iOS engine. That is slated to change in the coming PRs.
2019-08-12 12:32:38 -07:00

91 lines
2.3 KiB
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/message_loop.h"
#include <utility>
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/memory/ref_ptr.h"
#include "flutter/fml/message_loop_impl.h"
#include "flutter/fml/task_runner.h"
#include "flutter/fml/thread_local.h"
namespace fml {
FML_THREAD_LOCAL ThreadLocalUniquePtr<MessageLoop> tls_message_loop;
MessageLoop& MessageLoop::GetCurrent() {
auto* loop = tls_message_loop.get();
FML_CHECK(loop != nullptr)
<< "MessageLoop::EnsureInitializedForCurrentThread was not called on "
"this thread prior to message loop use.";
return *loop;
}
void MessageLoop::EnsureInitializedForCurrentThread() {
if (tls_message_loop.get() != nullptr) {
// Already initialized.
return;
}
tls_message_loop.reset(new MessageLoop());
}
bool MessageLoop::IsInitializedForCurrentThread() {
return tls_message_loop.get() != nullptr;
}
MessageLoop::MessageLoop()
: loop_(MessageLoopImpl::Create()),
task_runner_(fml::MakeRefCounted<fml::TaskRunner>(loop_)) {
FML_CHECK(loop_);
FML_CHECK(task_runner_);
}
MessageLoop::~MessageLoop() = default;
void MessageLoop::Run() {
loop_->DoRun();
}
void MessageLoop::Terminate() {
loop_->DoTerminate();
}
fml::RefPtr<fml::TaskRunner> MessageLoop::GetTaskRunner() const {
return task_runner_;
}
fml::RefPtr<MessageLoopImpl> MessageLoop::GetLoopImpl() const {
return loop_;
}
void MessageLoop::AddTaskObserver(intptr_t key, fml::closure callback) {
loop_->AddTaskObserver(key, callback);
}
void MessageLoop::RemoveTaskObserver(intptr_t key) {
loop_->RemoveTaskObserver(key);
}
void MessageLoop::RunExpiredTasksNow() {
loop_->RunExpiredTasksNow();
}
void MessageLoop::SwapTaskQueues(MessageLoop* other) {
FML_CHECK(loop_);
FML_CHECK(other->loop_);
loop_->SwapTaskQueues(other->loop_);
}
TaskQueueId MessageLoop::GetCurrentTaskQueueId() {
auto* loop = tls_message_loop.get();
FML_CHECK(loop != nullptr)
<< "MessageLoop::EnsureInitializedForCurrentThread was not called on "
"this thread prior to message loop use.";
return loop->GetLoopImpl()->GetTaskQueueId();
}
} // namespace fml