Update fml::ThreadPriority enum to match style guide. (flutter/engine#47255)
This commit is contained in:
@@ -21,13 +21,13 @@ class Thread {
|
||||
/// Valid values for priority of Thread.
|
||||
enum class ThreadPriority : int {
|
||||
/// Suitable for threads that shouldn't disrupt high priority work.
|
||||
BACKGROUND,
|
||||
kBackground,
|
||||
/// Default priority level.
|
||||
NORMAL,
|
||||
kNormal,
|
||||
/// Suitable for threads which generate data for the display.
|
||||
DISPLAY,
|
||||
kDisplay,
|
||||
/// Suitable for thread which raster data.
|
||||
RASTER,
|
||||
kRaster,
|
||||
};
|
||||
|
||||
/// The ThreadConfig is the thread info include thread name, thread priority.
|
||||
@@ -36,9 +36,9 @@ class Thread {
|
||||
: name(name), priority(priority) {}
|
||||
|
||||
explicit ThreadConfig(const std::string& name)
|
||||
: ThreadConfig(name, ThreadPriority::NORMAL) {}
|
||||
: ThreadConfig(name, ThreadPriority::kNormal) {}
|
||||
|
||||
ThreadConfig() : ThreadConfig("", ThreadPriority::NORMAL) {}
|
||||
ThreadConfig() : ThreadConfig("", ThreadPriority::kNormal) {}
|
||||
|
||||
std::string name;
|
||||
ThreadPriority priority;
|
||||
|
||||
@@ -62,7 +62,7 @@ static void MockThreadConfigSetter(const fml::Thread::ThreadConfig& config) {
|
||||
struct sched_param param;
|
||||
int policy = SCHED_OTHER;
|
||||
switch (config.priority) {
|
||||
case fml::Thread::ThreadPriority::DISPLAY:
|
||||
case fml::Thread::ThreadPriority::kDisplay:
|
||||
param.sched_priority = 10;
|
||||
break;
|
||||
default:
|
||||
@@ -77,7 +77,7 @@ TEST(Thread, ThreadPriorityCreatedWithConfig) {
|
||||
|
||||
fml::Thread thread(MockThreadConfigSetter,
|
||||
fml::Thread::ThreadConfig(
|
||||
thread1_name, fml::Thread::ThreadPriority::NORMAL));
|
||||
thread1_name, fml::Thread::ThreadPriority::kNormal));
|
||||
bool done = false;
|
||||
|
||||
struct sched_param param;
|
||||
@@ -95,7 +95,7 @@ TEST(Thread, ThreadPriorityCreatedWithConfig) {
|
||||
|
||||
fml::Thread thread2(MockThreadConfigSetter,
|
||||
fml::Thread::ThreadConfig(
|
||||
thread2_name, fml::Thread::ThreadPriority::DISPLAY));
|
||||
thread2_name, fml::Thread::ThreadPriority::kDisplay));
|
||||
thread2.GetTaskRunner()->PostTask([&]() {
|
||||
done = true;
|
||||
char thread_name[8];
|
||||
|
||||
@@ -41,21 +41,21 @@ static void AndroidPlatformThreadConfigSetter(
|
||||
fml::Thread::SetCurrentThreadName(config);
|
||||
// set thread priority
|
||||
switch (config.priority) {
|
||||
case fml::Thread::ThreadPriority::BACKGROUND: {
|
||||
case fml::Thread::ThreadPriority::kBackground: {
|
||||
fml::RequestAffinity(fml::CpuAffinity::kEfficiency);
|
||||
if (::setpriority(PRIO_PROCESS, 0, 10) != 0) {
|
||||
FML_LOG(ERROR) << "Failed to set IO task runner priority";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case fml::Thread::ThreadPriority::DISPLAY: {
|
||||
case fml::Thread::ThreadPriority::kDisplay: {
|
||||
fml::RequestAffinity(fml::CpuAffinity::kPerformance);
|
||||
if (::setpriority(PRIO_PROCESS, 0, -1) != 0) {
|
||||
FML_LOG(ERROR) << "Failed to set UI task runner priority";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case fml::Thread::ThreadPriority::RASTER: {
|
||||
case fml::Thread::ThreadPriority::kRaster: {
|
||||
fml::RequestAffinity(fml::CpuAffinity::kPerformance);
|
||||
// Android describes -8 as "most important display threads, for
|
||||
// compositing the screen and retrieving input events". Conservatively
|
||||
@@ -97,15 +97,15 @@ AndroidShellHolder::AndroidShellHolder(
|
||||
host_config.ui_config = fml::Thread::ThreadConfig(
|
||||
flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::UI, thread_label),
|
||||
fml::Thread::ThreadPriority::DISPLAY);
|
||||
fml::Thread::ThreadPriority::kDisplay);
|
||||
host_config.raster_config = fml::Thread::ThreadConfig(
|
||||
flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::RASTER, thread_label),
|
||||
fml::Thread::ThreadPriority::RASTER);
|
||||
fml::Thread::ThreadPriority::kRaster);
|
||||
host_config.io_config = fml::Thread::ThreadConfig(
|
||||
flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::IO, thread_label),
|
||||
fml::Thread::ThreadPriority::NORMAL);
|
||||
fml::Thread::ThreadPriority::kNormal);
|
||||
|
||||
thread_host_ = std::make_shared<ThreadHost>(host_config);
|
||||
|
||||
|
||||
@@ -48,18 +48,18 @@ static void IOSPlatformThreadConfigSetter(const fml::Thread::ThreadConfig& confi
|
||||
|
||||
// set thread priority
|
||||
switch (config.priority) {
|
||||
case fml::Thread::ThreadPriority::BACKGROUND: {
|
||||
case fml::Thread::ThreadPriority::kBackground: {
|
||||
pthread_set_qos_class_self_np(QOS_CLASS_BACKGROUND, 0);
|
||||
[[NSThread currentThread] setThreadPriority:0];
|
||||
break;
|
||||
}
|
||||
case fml::Thread::ThreadPriority::NORMAL: {
|
||||
case fml::Thread::ThreadPriority::kNormal: {
|
||||
pthread_set_qos_class_self_np(QOS_CLASS_DEFAULT, 0);
|
||||
[[NSThread currentThread] setThreadPriority:0.5];
|
||||
break;
|
||||
}
|
||||
case fml::Thread::ThreadPriority::RASTER:
|
||||
case fml::Thread::ThreadPriority::DISPLAY: {
|
||||
case fml::Thread::ThreadPriority::kRaster:
|
||||
case fml::Thread::ThreadPriority::kDisplay: {
|
||||
pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0);
|
||||
[[NSThread currentThread] setThreadPriority:1.0];
|
||||
sched_param param;
|
||||
@@ -805,17 +805,17 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
host_config.ui_config =
|
||||
fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::UI, threadLabel.UTF8String),
|
||||
fml::Thread::ThreadPriority::DISPLAY);
|
||||
fml::Thread::ThreadPriority::kDisplay);
|
||||
|
||||
host_config.raster_config =
|
||||
fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::RASTER, threadLabel.UTF8String),
|
||||
fml::Thread::ThreadPriority::RASTER);
|
||||
fml::Thread::ThreadPriority::kRaster);
|
||||
|
||||
host_config.io_config =
|
||||
fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::IO, threadLabel.UTF8String),
|
||||
fml::Thread::ThreadPriority::NORMAL);
|
||||
fml::Thread::ThreadPriority::kNormal);
|
||||
|
||||
return (flutter::ThreadHost){host_config};
|
||||
}
|
||||
|
||||
@@ -1978,16 +1978,16 @@ FlutterEngineResult FlutterEngineInitialize(size_t version,
|
||||
}
|
||||
FlutterThreadPriority priority = FlutterThreadPriority::kNormal;
|
||||
switch (config.priority) {
|
||||
case fml::Thread::ThreadPriority::BACKGROUND:
|
||||
case fml::Thread::ThreadPriority::kBackground:
|
||||
priority = FlutterThreadPriority::kBackground;
|
||||
break;
|
||||
case fml::Thread::ThreadPriority::NORMAL:
|
||||
case fml::Thread::ThreadPriority::kNormal:
|
||||
priority = FlutterThreadPriority::kNormal;
|
||||
break;
|
||||
case fml::Thread::ThreadPriority::DISPLAY:
|
||||
case fml::Thread::ThreadPriority::kDisplay:
|
||||
priority = FlutterThreadPriority::kDisplay;
|
||||
break;
|
||||
case fml::Thread::ThreadPriority::RASTER:
|
||||
case fml::Thread::ThreadPriority::kRaster:
|
||||
priority = FlutterThreadPriority::kRaster;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -137,9 +137,9 @@ EmbedderThreadHost::CreateEmbedderManagedThreadHost(
|
||||
//
|
||||
// If/when more task runners are exposed, this mask will need to be updated.
|
||||
thread_host_config.SetUIConfig(MakeThreadConfig(
|
||||
ThreadHost::Type::UI, fml::Thread::ThreadPriority::DISPLAY));
|
||||
ThreadHost::Type::UI, fml::Thread::ThreadPriority::kDisplay));
|
||||
thread_host_config.SetIOConfig(MakeThreadConfig(
|
||||
ThreadHost::Type::IO, fml::Thread::ThreadPriority::BACKGROUND));
|
||||
ThreadHost::Type::IO, fml::Thread::ThreadPriority::kBackground));
|
||||
|
||||
auto platform_task_runner_pair = CreateEmbedderTaskRunner(
|
||||
SAFE_ACCESS(custom_task_runners, platform_task_runner, nullptr));
|
||||
@@ -157,7 +157,7 @@ EmbedderThreadHost::CreateEmbedderManagedThreadHost(
|
||||
// created.
|
||||
if (!render_task_runner_pair.second) {
|
||||
thread_host_config.SetRasterConfig(MakeThreadConfig(
|
||||
ThreadHost::Type::RASTER, fml::Thread::ThreadPriority::RASTER));
|
||||
ThreadHost::Type::RASTER, fml::Thread::ThreadPriority::kRaster));
|
||||
}
|
||||
|
||||
// If both the platform task runner and the raster task runner are specified
|
||||
@@ -227,11 +227,11 @@ EmbedderThreadHost::CreateEngineManagedThreadHost(
|
||||
// Crate a thraed host config, and specified the thread name and priority.
|
||||
auto thread_host_config = ThreadHost::ThreadHostConfig(config_setter);
|
||||
thread_host_config.SetUIConfig(MakeThreadConfig(
|
||||
flutter::ThreadHost::UI, fml::Thread::ThreadPriority::DISPLAY));
|
||||
flutter::ThreadHost::UI, fml::Thread::ThreadPriority::kDisplay));
|
||||
thread_host_config.SetRasterConfig(MakeThreadConfig(
|
||||
flutter::ThreadHost::RASTER, fml::Thread::ThreadPriority::RASTER));
|
||||
flutter::ThreadHost::RASTER, fml::Thread::ThreadPriority::kRaster));
|
||||
thread_host_config.SetIOConfig(MakeThreadConfig(
|
||||
flutter::ThreadHost::IO, fml::Thread::ThreadPriority::BACKGROUND));
|
||||
flutter::ThreadHost::IO, fml::Thread::ThreadPriority::kBackground));
|
||||
|
||||
// Create a thread host with the current thread as the platform thread and all
|
||||
// other threads managed.
|
||||
|
||||
@@ -2577,7 +2577,7 @@ static void MockThreadConfigSetter(const fml::Thread::ThreadConfig& config) {
|
||||
struct sched_param param;
|
||||
int policy = SCHED_OTHER;
|
||||
switch (config.priority) {
|
||||
case fml::Thread::ThreadPriority::DISPLAY:
|
||||
case fml::Thread::ThreadPriority::kDisplay:
|
||||
param.sched_priority = 10;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -108,16 +108,16 @@ void SetThreadConfig(
|
||||
// the role naming scheme.
|
||||
std::string role;
|
||||
switch (config.priority) {
|
||||
case fml::Thread::ThreadPriority::BACKGROUND:
|
||||
case fml::Thread::ThreadPriority::kBackground:
|
||||
role = name_prefix + ".thread.background";
|
||||
break;
|
||||
case fml::Thread::ThreadPriority::DISPLAY:
|
||||
case fml::Thread::ThreadPriority::kDisplay:
|
||||
role = name_prefix + ".thread.display";
|
||||
break;
|
||||
case fml::Thread::ThreadPriority::RASTER:
|
||||
case fml::Thread::ThreadPriority::kRaster:
|
||||
role = name_prefix + ".thread.raster";
|
||||
break;
|
||||
case fml::Thread::ThreadPriority::NORMAL:
|
||||
case fml::Thread::ThreadPriority::kNormal:
|
||||
role = name_prefix + ".thread.normal";
|
||||
break;
|
||||
default:
|
||||
@@ -186,15 +186,15 @@ flutter::ThreadHost Engine::CreateThreadHost(
|
||||
thread_host_config.SetRasterConfig(
|
||||
{flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::RASTER, name_prefix),
|
||||
fml::Thread::ThreadPriority::RASTER});
|
||||
fml::Thread::ThreadPriority::kRaster});
|
||||
thread_host_config.SetUIConfig(
|
||||
{flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::UI, name_prefix),
|
||||
fml::Thread::ThreadPriority::DISPLAY});
|
||||
fml::Thread::ThreadPriority::kDisplay});
|
||||
thread_host_config.SetIOConfig(
|
||||
{flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
|
||||
flutter::ThreadHost::Type::IO, name_prefix),
|
||||
fml::Thread::ThreadPriority::NORMAL});
|
||||
fml::Thread::ThreadPriority::kNormal});
|
||||
|
||||
return flutter::ThreadHost(thread_host_config);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user