点击蓝字 ╳ 关注我们
吴文璐
深圳开鸿数字产业发展有限公司
OS框架开发工程师
一、前言
二、ArkUI中的线程
void AceContainer::InitializeTask()
{
auto flutterTaskExecutor = Referenced::MakeRefPtr();
flutterTaskExecutor->InitPlatformThread(useCurrentEventRunner_);
taskExecutor_ = flutterTaskExecutor;
// No need to create JS Thread for DECLARATIVE_JS
if (type_ == FrontendType::DECLARATIVE_JS) {
GetSettings().useUIAsJSThread = true;
} else {
flutterTaskExecutor->InitJsThread();
}
}
enum class TaskType : uint32_t {
PLATFORM = 0,
UI,
IO,
GPU,
JS,
BACKGROUND,
UNKNOWN,
};
auto&& touchEventCallback = [context = pipelineContext_, id = instanceId_](
const TouchEvent& event, const std::function& markProcess) {
ContainerScope scope(id);
context->GetTaskExecutor()->PostTask(
[context, event, markProcess]() {
context->OnTouchEvent(event);
CHECK_NULL_VOID_NOLOG(markProcess);
markProcess();
},
TaskExecutor::UI);
};
三、各种类型的TaskRunner如何初始化?
void FlutterTaskExecutor::InitPlatformThread(bool useCurrentEventRunner)
{
#ifdef OHOS_STANDARD_SYSTEM
platformRunner_ = flutter::CurrentTaskRunner(useCurrentEventRunner);
#else
fml::EnsureInitializedForCurrentThread();
platformRunner_ = fml::GetCurrent().GetTaskRunner();
#endif
FillTaskTypeTable(TaskType::PLATFORM);
}
fml::RefPtr PlatformTaskRunner::CurrentTaskRunner(bool useCurrentEventRunner)
{
return PlatformTaskRunnerAdapter::CurrentTaskRunner(useCurrentEventRunner);
}
fml::RefPtr PlatformTaskRunnerAdapter::CurrentTaskRunner(bool useCurrentEventRunner)
{
if (useCurrentEventRunner) {
return fml::MakeRefCounted(useCurrentEventRunner);
}
if (taskRunner_) {
return taskRunner_;
}
taskRunner_ = fml::MakeRefCounted(useCurrentEventRunner);
return taskRunner_;
}
PlatformTaskRunnerAdapter::PlatformTaskRunnerAdapter(bool useCurrentEventRunner)
: fml::TaskRunner(nullptr)
{
if (useCurrentEventRunner) {
eventRunner_ = OHOS::Current();
} else {
eventRunner_ = OHOS::GetMainEventRunner();
}
eventHandler_ = std::make_shared(eventRunner_);
}
void PlatformTaskRunnerAdapter::closure task)
{
eventHandler_->PostTask(std::move(task));
}
void FlutterTaskExecutor::InitOtherThreads(const flutter::TaskRunners& taskRunners)
{
uiRunner_ = taskRunners.GetUITaskRunner();
ioRunner_ = taskRunners.GetIOTaskRunner();
#ifdef NG_BUILD
gpuRunner_ = taskRunners.GetRasterTaskRunner();
#else
gpuRunner_ = taskRunners.GetGPUTaskRunner();
#endif
//...此处省略若干行
}
FlutterAceView* FlutterAceView::CreateView(int32_t instanceId, bool useCurrentEventRunner, bool usePlatformThread)
{
FlutterAceView* aceSurface = new Platform::FlutterAceView(instanceId);
if (aceSurface != nullptr) {
aceSurface->IncRefCount();
}
flutter::Settings settings;
settings.instanceId = instanceId;
settings.platform = flutter::ACE_PLATFORM_OHOS;
#ifndef GPU_DISABLED
settings.enable_software_rendering = false;
#else
settings.enable_software_rendering = true;
#endif
#ifdef ENABLE_ROSEN_BACKEND
settings.use_system_render_thread = SystemProperties::GetRosenBackendEnabled();
#endif
settings.platform_as_ui_thread = usePlatformThread;
settings.use_current_event_runner = useCurrentEventRunner;
// ...此处省略若干行
auto shell_holder = std::make_unique(settings, false);
if (aceSurface != nullptr) {
aceSurface->SetShellHolder(std::move(shell_holder));
}
return aceSurface;
}
OhosShellHolder::OhosShellHolder(
flutter::Settings settings,
bool is_background_view)
: settings_(std::move(settings))
{
// ...此处省略若干行
// The current thread will be used as the platform thread. Ensure that the
// message loop is initialized.
fml::EnsureInitializedForCurrentThread();
fml::RefPtr gpu_runner;
fml::RefPtr ui_runner;
fml::RefPtr io_runner;
fml::RefPtr platform_runner =
PlatformTaskRunnerAdapter::CurrentTaskRunner(settings_.use_current_event_runner);
if (is_background_view) {
auto single_task_runner = thread_host_.ui_thread->GetTaskRunner();
gpu_runner = single_task_runner;
ui_runner = single_task_runner;
io_runner = single_task_runner;
} else {
if (settings_.platform_as_ui_thread) {
ui_runner = platform_runner;
} else {
ui_runner = thread_host_.ui_thread->GetTaskRunner();
}
if (!settings_.use_system_render_thread) {
gpu_runner = thread_host_.gpu_thread->GetTaskRunner();
} else {
gpu_runner = ui_runner;
}
if (settings_.use_io_thread) {
io_runner = thread_host_.io_thread->GetTaskRunner();
} else {
io_runner = ui_runner;
}
}
flutter::TaskRunners task_runners(thread_label, // label
platform_runner, // platform
gpu_runner, // gpu
ui_runner, // ui
io_runner // io
);
void FlutterTaskExecutor::InitJsThread(bool newThread)
{
if (newThread) {
jsThread_ = std::make_unique(GenJsThreadName());
jsRunner_ = jsThread_->GetTaskRunner();
} else {
jsRunner_ = uiRunner_;
}
PostTaskToTaskRunner(
jsRunner_, [weak = AceType::WeakClaim(this)] { FillTaskTypeTable(weak, TaskType::JS); }, 0);
}
void RosenFontLoader::LoadFromNetwork(const OHOS::RefPtr& context)
{
auto weakContext = AceType::RawPtr(context));
context->GetTaskExecutor()->PostTask(
[weak = AceType::WeakClaim(this), weakContext] {
auto fontLoader = weak.Upgrade();
auto context = weakContext.Upgrade();
if (!fontLoader || !context) {
return;
}
std::vector fontData;
if (!DownloadManager::GetInstance().Download(fontLoader->familySrc_, fontData) || fontData.empty()) {
return;
}
//...此处省略若干行
},
TaskExecutor::BACKGROUND);
}
四、ArkUI中的看门狗
原文标题:ArkUI中的线程和看门狗机制
文章出处:【微信公众号:OpenAtom OpenHarmony】欢迎添加关注!文章转载请注明出处。
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
举报投诉
-
鸿蒙
+关注
关注
57文章
2305浏览量
42711 -
OpenHarmony
+关注
关注
25文章
3649浏览量
16100
原文标题:ArkUI中的线程和看门狗机制
文章出处:【微信号:gh_e4f28cfa3159,微信公众号:OpenAtom OpenHarmony】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
单片机开发:使用内部看门狗定时器(WDT)还是外挂看门狗芯片?
在电子产品中,有时候需要看门狗定时器(WDT),看门狗芯片有外部和内置两种。在设计之初,要不要使用看门狗芯片?这是个值得考虑的问题。在本文中,英锐恩技术工程师对内部和外部
发表于 09-25 13:46
软件看门狗和硬件看门狗的区别
软件看门狗和硬件看门狗都是用于监控系统崩溃的工具,它们的作用是在系统出现故障或异常情况时自动恢复系统。 软件看门狗是一种程序,运行在操作系统中,通过定时检测系统是否正常运行来判断系统
TLF35584中集成的看门狗工作应用案例
看门狗输入引脚 WDI 具有集成的下拉电流 IWDI 。看门狗输入 WDI 可以在“Closed Window”内或随后的“Open Window”期间转换为高电平。
发表于 03-18 11:27
•3565次阅读
芯知识 | 语音芯片中的声音播放提示IC内置看门狗的作用介绍
随着科技的不断发展,语音芯片在各个领域的应用越来越广泛。其中,声音播放提示IC作为语音芯片的重要组成部分,其功能和性能的提升对于产品的用户体验和稳定性至关重要。而在声音播放提示IC中,内置看门狗
UVM环境的看门狗怎么没看住超时了?
uvm验证环境里一般通过objection机制来控制仿真的结束,不过在机制之外,有时还需要通过看门狗来watchdog避免仿真环境挂死,watchdog配合objection一起来控制仿真的进行与结束。
MCU看门狗应用注意事项
我们使用的MCU是普冉的PY32F030,这颗芯片在低功耗应用场景下,使用看门狗会有很多的问题和缺陷,需要非常注意,稍有不慎,就会出问题。
发表于 12-02 09:47
•1099次阅读
什么是模拟看门狗?模拟看门狗有什么用处?
看门狗大家应该再熟悉不过了,一旦忘记喂狗就会导致单片机复位,而在大部分stm32中都存在两种类型的看门狗,Independent watchdog (IWDG)独立看门狗和Window
评论