Commit d317bfde authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[ThreadPool] Add a feature to disable priority inheritance

Details @ https://docs.google.com/document/d/13PIBPuSPJbrgHAgyRbY22EWAfH2narnxpa_CgBmZbSY/edit

R=fdoray@chromium.org

Bug: 1022972
Change-Id: I89b0404b28c92fc144b40352eed95a847f1a19ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906637
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Auto-Submit: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714441}
parent b3fdf35b
......@@ -31,4 +31,7 @@ const Feature kUseNativeThreadPool = {"UseNativeThreadPool",
const Feature kUseFiveMinutesThreadReclaimTime = {
"UseFiveMinutesThreadReclaimTime", base::FEATURE_DISABLED_BY_DEFAULT};
const Feature kNoPriorityInheritanceFromThreadPool{
"NoPriorityInheritanceFromThreadPool", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace base
......@@ -41,6 +41,12 @@ extern const BASE_EXPORT Feature kUseNativeThreadPool;
// minutes, instead of 30 seconds.
extern const BASE_EXPORT Feature kUseFiveMinutesThreadReclaimTime;
// Under this feature, the current default of inheriting priority when posting
// from the ThreadPool is disabled.
// Details @
// https://docs.google.com/document/d/13PIBPuSPJbrgHAgyRbY22EWAfH2narnxpa_CgBmZbSY
extern const BASE_EXPORT Feature kNoPriorityInheritanceFromThreadPool;
} // namespace base
#endif // BASE_TASK_TASK_FEATURES_H_
......@@ -12,6 +12,17 @@
namespace base {
// The state of |FeatureList::IsEnabled(kNoPriorityInheritanceFromThreadPool)|
// as controlled by intenal::SetNoPriorityInheritanceFromThreadPool().
bool g_no_priority_inheritance_from_thread_pool = false;
void TaskTraits::InheritPriority(TaskPriority priority) {
if (priority_set_explicitly() || g_no_priority_inheritance_from_thread_pool)
return;
priority_ = static_cast<uint8_t>(priority);
}
const char* TaskPriorityToString(TaskPriority task_priority) {
switch (task_priority) {
case TaskPriority::BEST_EFFORT:
......@@ -50,4 +61,10 @@ std::ostream& operator<<(std::ostream& os,
return os;
}
namespace internal {
void SetNoPriorityInheritanceFromThreadPool() {
g_no_priority_inheritance_from_thread_pool = true;
}
} // namespace internal
} // namespace base
......@@ -304,11 +304,7 @@ class BASE_EXPORT TaskTraits {
}
// Sets the priority to |priority| if it wasn't explicitly set before.
void InheritPriority(TaskPriority priority) {
if (priority_set_explicitly())
return;
priority_ = static_cast<uint8_t>(priority);
}
void InheritPriority(TaskPriority priority);
// Returns true if the priority was set explicitly.
constexpr bool priority_set_explicitly() const {
......@@ -418,6 +414,13 @@ BASE_EXPORT std::ostream& operator<<(
std::ostream& os,
const TaskShutdownBehavior& shutdown_behavior);
namespace internal {
// Enables the kNoPriorityInheritanceFromThreadPool experimental feature. Must
// be done statically when the ThreadPoolImpl is initialized because it's racy
// to check the state later.
void SetNoPriorityInheritanceFromThreadPool();
} // namespace internal
} // namespace base
#endif // BASE_TASK_TASK_TRAITS_H_
......@@ -123,6 +123,9 @@ void ThreadPoolImpl::Start(const ThreadPoolInstance::InitParams& init_params,
internal::InitializeThreadPrioritiesFeature();
if (FeatureList::IsEnabled(kNoPriorityInheritanceFromThreadPool))
internal::SetNoPriorityInheritanceFromThreadPool();
// The max number of concurrent BEST_EFFORT tasks is |kMaxBestEffortTasks|,
// unless the max number of foreground threads is lower.
const int max_best_effort_tasks =
......
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