#include "base/task/thread_pool/thread_pool_impl.h"
#include <algorithm>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/leak_annotations.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/message_loop/message_pump.h"
#include "base/message_loop/message_pump_type.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_util.h"
#include "base/system/sys_info.h"
#include "base/task/scoped_set_task_priority_for_current_thread.h"
#include "base/task/thread_pool/pooled_parallel_task_runner.h"
#include "base/task/thread_pool/pooled_sequenced_task_runner.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/task_source.h"
#include "base/task/thread_pool/task_source_sort_key.h"
#include "base/task/thread_pool/thread_group_impl.h"
#include "base/task/thread_pool/worker_thread.h"
#include "base/thread_annotations.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
namespace base {
namespace internal {
namespace {
constexpr EnvironmentParams kForegroundPoolEnvironmentParams{ … };
constexpr EnvironmentParams kUtilityPoolEnvironmentParams{ … };
constexpr EnvironmentParams kBackgroundPoolEnvironmentParams{ … };
constexpr size_t kMaxBestEffortTasks = …;
bool HasDisableBestEffortTasksSwitch() { … }
bool g_synchronous_thread_start_for_testing = …;
}
ThreadPoolImpl::ThreadPoolImpl(std::string_view histogram_label)
: … { … }
ThreadPoolImpl::ThreadPoolImpl(std::string_view histogram_label,
std::unique_ptr<TaskTrackerImpl> task_tracker,
bool use_background_threads)
: … { … }
ThreadPoolImpl::~ThreadPoolImpl() { … }
void ThreadPoolImpl::Start(const ThreadPoolInstance::InitParams& init_params,
WorkerThreadObserver* worker_thread_observer) { … }
bool ThreadPoolImpl::WasStarted() const { … }
bool ThreadPoolImpl::WasStartedUnsafe() const { … }
void ThreadPoolImpl::BeginRestrictedTasks() { … }
void ThreadPoolImpl::EndRestrictedTasks() { … }
bool ThreadPoolImpl::PostDelayedTask(const Location& from_here,
const TaskTraits& traits,
OnceClosure task,
TimeDelta delay) { … }
scoped_refptr<TaskRunner> ThreadPoolImpl::CreateTaskRunner(
const TaskTraits& traits) { … }
scoped_refptr<SequencedTaskRunner> ThreadPoolImpl::CreateSequencedTaskRunner(
const TaskTraits& traits) { … }
scoped_refptr<SingleThreadTaskRunner>
ThreadPoolImpl::CreateSingleThreadTaskRunner(
const TaskTraits& traits,
SingleThreadTaskRunnerThreadMode thread_mode) { … }
#if BUILDFLAG(IS_WIN)
scoped_refptr<SingleThreadTaskRunner> ThreadPoolImpl::CreateCOMSTATaskRunner(
const TaskTraits& traits,
SingleThreadTaskRunnerThreadMode thread_mode) {
return single_thread_task_runner_manager_.CreateCOMSTATaskRunner(traits,
thread_mode);
}
#endif
scoped_refptr<UpdateableSequencedTaskRunner>
ThreadPoolImpl::CreateUpdateableSequencedTaskRunner(const TaskTraits& traits) { … }
std::optional<TimeTicks> ThreadPoolImpl::NextScheduledRunTimeForTesting()
const { … }
void ThreadPoolImpl::ProcessRipeDelayedTasksForTesting() { … }
void ThreadPoolImpl::SetSynchronousThreadStartForTesting(bool enabled) { … }
size_t ThreadPoolImpl::GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated(
const TaskTraits& traits) const { … }
void ThreadPoolImpl::Shutdown() { … }
void ThreadPoolImpl::FlushForTesting() { … }
void ThreadPoolImpl::FlushAsyncForTesting(OnceClosure flush_callback) { … }
void ThreadPoolImpl::JoinForTesting() { … }
void ThreadPoolImpl::BeginFence() { … }
void ThreadPoolImpl::EndFence() { … }
void ThreadPoolImpl::BeginBestEffortFence() { … }
void ThreadPoolImpl::EndBestEffortFence() { … }
void ThreadPoolImpl::BeginFizzlingBlockShutdownTasks() { … }
void ThreadPoolImpl::EndFizzlingBlockShutdownTasks() { … }
bool ThreadPoolImpl::PostTaskWithSequenceNow(Task task,
scoped_refptr<Sequence> sequence) { … }
bool ThreadPoolImpl::PostTaskWithSequence(Task task,
scoped_refptr<Sequence> sequence) { … }
bool ThreadPoolImpl::ShouldYield(const TaskSource* task_source) { … }
bool ThreadPoolImpl::EnqueueJobTaskSource(
scoped_refptr<JobTaskSource> task_source) { … }
void ThreadPoolImpl::RemoveJobTaskSource(
scoped_refptr<JobTaskSource> task_source) { … }
void ThreadPoolImpl::UpdatePriority(scoped_refptr<TaskSource> task_source,
TaskPriority priority) { … }
void ThreadPoolImpl::UpdateJobPriority(scoped_refptr<TaskSource> task_source,
TaskPriority priority) { … }
const ThreadGroup* ThreadPoolImpl::GetThreadGroupForTraits(
const TaskTraits& traits) const { … }
ThreadGroup* ThreadPoolImpl::GetThreadGroupForTraits(const TaskTraits& traits) { … }
void ThreadPoolImpl::UpdateCanRunPolicy() { … }
}
}