Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1e8ccc1

Browse files
committed
Fix Android IO and Worker threads priority issue
1 parent 08daa2c commit 1e8ccc1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

fml/concurrent_message_loop.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "flutter/fml/concurrent_message_loop.h"
66

7+
#include <sys/resource.h>
8+
#include <unistd.h>
79
#include <algorithm>
810

911
#include "flutter/fml/thread.h"
@@ -21,6 +23,9 @@ ConcurrentMessageLoop::ConcurrentMessageLoop(size_t worker_count)
2123
: worker_count_(std::max<size_t>(worker_count, 1ul)) {
2224
for (size_t i = 0; i < worker_count_; ++i) {
2325
workers_.emplace_back([i, this]() {
26+
#if OS_ANDROID
27+
::setpriority(PRIO_PROCESS, gettid(), 1);
28+
#endif
2429
fml::Thread::SetCurrentThreadName(
2530
std::string{"io.flutter.worker." + std::to_string(i + 1)});
2631
WorkerMain();

shell/platform/android/android_shell_holder.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ AndroidShellHolder::AndroidShellHolder(
122122
FML_LOG(ERROR) << "Failed to set UI task runner priority";
123123
}
124124
});
125+
task_runners.GetIOTaskRunner()->PostTask([]() {
126+
if (::setpriority(PRIO_PROCESS, gettid(), 1) != 0) {
127+
FML_LOG(ERROR) << "Failed to set IO task runner priority";
128+
}
129+
});
125130

126131
shell_ =
127132
Shell::Create(task_runners, // task runners

0 commit comments

Comments
 (0)