#include "cc/raster/categorized_worker_pool.h"
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequence_manager/task_time_observer.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/trace_event/typed_macros.h"
#include "build/build_config.h"
#include "cc/base/math_util.h"
#include "cc/base/switches.h"
#include "cc/raster/task_category.h"
namespace cc {
namespace {
BASE_FEATURE(…);
constexpr TaskCategory kNormalThreadPriorityCategories[] = …;
constexpr TaskCategory kBackgroundThreadPriorityCategories[] = …;
constexpr TaskCategory kForegroundCategories[] = …;
constexpr TaskCategory kBackgroundCategories[] = …;
class CategorizedWorkerPoolThread : public base::SimpleThread { … };
scoped_refptr<CategorizedWorkerPool>& GetWorkerPool() { … }
}
class CategorizedWorkerPool::CategorizedWorkerPoolSequencedTaskRunner
: public base::SequencedTaskRunner { … };
CategorizedWorkerPoolImpl::CategorizedWorkerPoolImpl(Delegate* delegate)
: … { … }
CategorizedWorkerPoolImpl::~CategorizedWorkerPoolImpl() = default;
void CategorizedWorkerPoolImpl::Start(int max_concurrency_foreground) { … }
void CategorizedWorkerPoolImpl::Shutdown() { … }
void CategorizedWorkerPoolImpl::ThreadWillRun(base::PlatformThreadId tid) { … }
bool CategorizedWorkerPoolImpl::PostDelayedTask(const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) { … }
void CategorizedWorkerPoolImpl::Run(
const std::vector<TaskCategory>& categories,
base::ConditionVariable* has_ready_to_run_tasks_cv) { … }
void CategorizedWorkerPoolImpl::FlushForTesting() { … }
void CategorizedWorkerPoolImpl::ScheduleTasks(NamespaceToken token,
TaskGraph* graph) { … }
void CategorizedWorkerPoolImpl::ScheduleTasksWithLockAcquired(
NamespaceToken token,
TaskGraph* graph) { … }
bool CategorizedWorkerPoolImpl::RunTaskWithLockAcquired(
const std::vector<TaskCategory>& categories) { … }
void CategorizedWorkerPoolImpl::RunTaskInCategoryWithLockAcquired(
TaskCategory category) { … }
void CategorizedWorkerPoolImpl::SignalHasReadyToRunTasksWithLockAcquired() { … }
CategorizedWorkerPoolJob::CategorizedWorkerPoolJob() = default;
CategorizedWorkerPoolJob::~CategorizedWorkerPoolJob() = default;
void CategorizedWorkerPoolJob::Start(int max_concurrency_foreground) { … }
void CategorizedWorkerPoolJob::Shutdown() { … }
bool CategorizedWorkerPoolJob::PostDelayedTask(const base::Location& from_here,
base::OnceClosure task,
base::TimeDelta delay) { … }
void CategorizedWorkerPoolJob::Run(base::span<const TaskCategory> categories,
base::JobDelegate* job_delegate) { … }
std::optional<TaskGraphWorkQueue::PrioritizedTask>
CategorizedWorkerPoolJob::GetNextTaskToRunWithLockAcquired(
base::span<const TaskCategory> categories) { … }
void CategorizedWorkerPoolJob::FlushForTesting() { … }
void CategorizedWorkerPoolJob::ScheduleTasks(NamespaceToken token,
TaskGraph* graph) { … }
base::JobHandle* CategorizedWorkerPoolJob::ScheduleTasksWithLockAcquired(
NamespaceToken token,
TaskGraph* graph) { … }
base::JobHandle*
CategorizedWorkerPoolJob::GetJobHandleToNotifyWithLockAcquired() { … }
size_t CategorizedWorkerPoolJob::GetMaxJobConcurrency(
base::span<const TaskCategory> categories) const { … }
CategorizedWorkerPool* CategorizedWorkerPool::GetOrCreate(Delegate* delegate) { … }
CategorizedWorkerPool::CategorizedWorkerPool()
: … { … }
scoped_refptr<base::SequencedTaskRunner>
CategorizedWorkerPool::CreateSequencedTaskRunner() { … }
CategorizedWorkerPool::~CategorizedWorkerPool() = default;
NamespaceToken CategorizedWorkerPool::GenerateNamespaceToken() { … }
void CategorizedWorkerPool::WaitForTasksToFinishRunning(NamespaceToken token) { … }
void CategorizedWorkerPool::CollectCompletedTasks(
NamespaceToken token,
Task::Vector* completed_tasks) { … }
void CategorizedWorkerPool::CollectCompletedTasksWithLockAcquired(
NamespaceToken token,
Task::Vector* completed_tasks) { … }
bool CategorizedWorkerPool::ShouldRunTaskForCategoryWithLockAcquired(
TaskCategory category) { … }
CategorizedWorkerPool::ClosureTask::ClosureTask(base::OnceClosure closure)
: … { … }
void CategorizedWorkerPool::ClosureTask::RunOnWorkerThread() { … }
CategorizedWorkerPool::ClosureTask::~ClosureTask() { … }
}