#include "base/task/thread_pool/worker_thread.h"
#include <stddef.h>
#include <algorithm>
#include <atomic>
#include <optional>
#include <utility>
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/debug/alias.h"
#include "base/feature_list.h"
#include "base/functional/callback_helpers.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/task_features.h"
#include "base/task/thread_pool/environment_config.h"
#include "base/task/thread_pool/worker_thread_observer.h"
#include "base/threading/hang_watcher.h"
#include "base/time/time.h"
#include "base/time/time_override.h"
#include "base/trace_event/base_tracing.h"
#include "build/build_config.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/partition_alloc_config.h"
#if (BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL)) || BUILDFLAG(IS_FUCHSIA)
#include "base/files/file_descriptor_watcher_posix.h"
#endif
#if BUILDFLAG(IS_APPLE)
#include "base/apple/scoped_nsautorelease_pool.h"
#endif
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
PA_CONFIG(THREAD_CACHE_SUPPORTED)
#include "partition_alloc/thread_cache.h"
#endif
namespace base::internal {
constexpr TimeDelta WorkerThread::Delegate::kPurgeThreadCacheIdleDelay;
WorkerThread::ThreadLabel WorkerThread::Delegate::GetThreadLabel() const { … }
bool WorkerThread::Delegate::TimedWait(TimeDelta timeout) { … }
void WorkerThread::Delegate::WaitForWork() { … }
bool WorkerThread::Delegate::IsDelayFirstWorkerSleepEnabled() { … }
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
PA_CONFIG(THREAD_CACHE_SUPPORTED)
TimeDelta WorkerThread::Delegate::GetSleepDurationBeforePurge(TimeTicks now) { … }
#endif
WorkerThread::WorkerThread(ThreadType thread_type_hint,
std::unique_ptr<Delegate> delegate,
TrackedRef<TaskTracker> task_tracker,
size_t sequence_num,
const CheckedLock* predecessor_lock,
void* flow_terminator)
: … { … }
bool WorkerThread::Start(
scoped_refptr<SingleThreadTaskRunner> io_thread_task_runner,
WorkerThreadObserver* worker_thread_observer) { … }
void WorkerThread::Destroy() { … }
bool WorkerThread::ThreadAliveForTesting() const { … }
void WorkerThread::JoinForTesting() { … }
void WorkerThread::Cleanup() { … }
void WorkerThread::WakeUp() { … }
WorkerThread::Delegate* WorkerThread::delegate() { … }
WorkerThread::~WorkerThread() { … }
void WorkerThread::MaybeUpdateThreadType() { … }
void WorkerThread::BeginUnusedPeriod() { … }
void WorkerThread::EndUnusedPeriod() { … }
TimeTicks WorkerThread::GetLastUsedTime() const { … }
bool WorkerThread::ShouldExit() const { … }
ThreadType WorkerThread::GetDesiredThreadType() const { … }
void WorkerThread::UpdateThreadType(ThreadType desired_thread_type) { … }
void WorkerThread::ThreadMain() { … }
NOINLINE void WorkerThread::RunPooledWorker() { … }
NOINLINE void WorkerThread::RunBackgroundPooledWorker() { … }
NOINLINE void WorkerThread::RunSharedWorker() { … }
NOINLINE void WorkerThread::RunBackgroundSharedWorker() { … }
NOINLINE void WorkerThread::RunDedicatedWorker() { … }
NOINLINE void WorkerThread::RunBackgroundDedicatedWorker() { … }
#if BUILDFLAG(IS_WIN)
NOINLINE void WorkerThread::RunSharedCOMWorker() {
RunWorker();
NO_CODE_FOLDING();
}
NOINLINE void WorkerThread::RunBackgroundSharedCOMWorker() {
RunWorker();
NO_CODE_FOLDING();
}
NOINLINE void WorkerThread::RunDedicatedCOMWorker() {
RunWorker();
NO_CODE_FOLDING();
}
NOINLINE void WorkerThread::RunBackgroundDedicatedCOMWorker() {
RunWorker();
NO_CODE_FOLDING();
}
#endif
void WorkerThread::RunWorker() { … }
}