#include "base/threading/platform_thread.h"
#include <errno.h>
#include <pthread.h>
#include <sched.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <memory>
#include <tuple>
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/notimplemented.h"
#include "base/threading/platform_thread_internal_posix.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/thread_id_name_manager.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "partition_alloc/buildflags.h"
#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_FUCHSIA) && !BUILDFLAG(IS_NACL)
#include "base/posix/can_lower_nice_to.h"
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include <sys/syscall.h>
#include <atomic>
#endif
#if BUILDFLAG(IS_FUCHSIA)
#include <lib/zx/thread.h>
#include "base/fuchsia/koid.h"
#else
#include <sys/resource.h>
#endif
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
#include "partition_alloc/stack/stack.h"
#endif
namespace base {
void InitThreading();
void TerminateOnThread();
size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes);
namespace {
struct ThreadParams { … };
void* ThreadFunc(void* params) { … }
bool CreateThread(size_t stack_size,
bool joinable,
PlatformThread::Delegate* delegate,
PlatformThreadHandle* thread_handle,
ThreadType thread_type,
MessagePumpType message_pump_type) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
thread_local pid_t g_thread_id = …;
std::atomic<bool> g_main_thread_tid_cache_valid = …;
thread_local bool g_is_main_thread = …;
class InitAtFork { … };
#endif
}
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
namespace internal {
void InvalidateTidCache() { … }
}
#endif
PlatformThreadId PlatformThreadBase::CurrentId() { … }
PlatformThreadRef PlatformThreadBase::CurrentRef() { … }
PlatformThreadHandle PlatformThreadBase::CurrentHandle() { … }
#if !BUILDFLAG(IS_APPLE)
void PlatformThreadBase::YieldCurrentThread() { … }
#endif
void PlatformThreadBase::Sleep(TimeDelta duration) { … }
const char* PlatformThreadBase::GetName() { … }
bool PlatformThreadBase::CreateWithType(size_t stack_size,
Delegate* delegate,
PlatformThreadHandle* thread_handle,
ThreadType thread_type,
MessagePumpType pump_type_hint) { … }
bool PlatformThreadBase::CreateNonJoinable(size_t stack_size, Delegate* delegate) { … }
bool PlatformThreadBase::CreateNonJoinableWithType(size_t stack_size,
Delegate* delegate,
ThreadType thread_type,
MessagePumpType pump_type_hint) { … }
void PlatformThreadBase::Join(PlatformThreadHandle thread_handle) { … }
void PlatformThreadBase::Detach(PlatformThreadHandle thread_handle) { … }
#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_FUCHSIA)
bool PlatformThreadBase::CanChangeThreadType(ThreadType from, ThreadType to) { … }
namespace internal {
void SetCurrentThreadTypeImpl(ThreadType thread_type,
MessagePumpType pump_type_hint) { … }
}
ThreadPriorityForTest PlatformThreadBase::GetCurrentThreadPriorityForTest() { … }
#endif
size_t PlatformThreadBase::GetDefaultThreadStackSize() { … }
}