#ifndef BASE_THREADING_PLATFORM_THREAD_H_
#define BASE_THREADING_PLATFORM_THREAD_H_
#include <stddef.h>
#include <iosfwd>
#include <optional>
#include <type_traits>
#include "base/base_export.h"
#include "base/message_loop/message_pump_type.h"
#include "base/process/process_handle.h"
#include "base/sequence_checker_impl.h"
#include "base/threading/platform_thread_ref.h"
#include "base/time/time.h"
#include "base/types/strong_alias.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#elif BUILDFLAG(IS_FUCHSIA)
#include <zircon/types.h>
#elif BUILDFLAG(IS_APPLE)
#include <mach/mach_types.h>
#elif BUILDFLAG(IS_POSIX)
#include <pthread.h>
#include <unistd.h>
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "base/feature_list.h"
#endif
namespace base {
#if BUILDFLAG(IS_WIN)
typedef DWORD PlatformThreadId;
#elif BUILDFLAG(IS_FUCHSIA)
typedef zx_koid_t PlatformThreadId;
#elif BUILDFLAG(IS_APPLE)
typedef mach_port_t PlatformThreadId;
#elif BUILDFLAG(IS_POSIX)
PlatformThreadId;
#endif
static_assert …;
class PlatformThreadHandle { … };
const PlatformThreadId kInvalidThreadId(0);
enum class ThreadType : int { … };
enum class ThreadPriorityForTest : int { … };
class BASE_EXPORT PlatformThreadBase { … };
#if BUILDFLAG(IS_APPLE)
class BASE_EXPORT PlatformThreadApple : public PlatformThreadBase {
public:
static void SetCurrentThreadRealtimePeriodValue(TimeDelta realtime_period);
static TimeDelta GetCurrentThreadRealtimePeriodForTest();
static void InitializeFeatures();
};
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
class ThreadTypeDelegate;
IsViaIPC;
class BASE_EXPORT PlatformThreadLinux : public PlatformThreadBase { … };
#endif
#if BUILDFLAG(IS_CHROMEOS)
BASE_EXPORT BASE_DECLARE_FEATURE(kSetRtForDisplayThreads);
class CrossProcessPlatformThreadDelegate;
class BASE_EXPORT PlatformThreadChromeOS : public PlatformThreadLinux {
public:
static void SetCrossProcessPlatformThreadDelegate(
CrossProcessPlatformThreadDelegate* delegate);
static void InitializeFeatures();
static void SetThreadType(PlatformThreadId process_id,
PlatformThreadId thread_id,
ThreadType thread_type,
IsViaIPC via_ipc);
static bool IsThreadsBgFeatureEnabled();
static bool IsDisplayThreadsRtFeatureEnabled();
static void SetThreadBackgrounded(ProcessId process_id,
PlatformThreadId thread_id,
bool backgrounded);
static std::optional<ThreadType> GetThreadTypeFromThreadId(
ProcessId process_id,
PlatformThreadId thread_id);
static SequenceCheckerImpl& GetCrossProcessThreadPrioritySequenceChecker();
};
#endif
#if BUILDFLAG(IS_APPLE)
using PlatformThread = PlatformThreadApple;
#elif BUILDFLAG(IS_CHROMEOS)
using PlatformThread = PlatformThreadChromeOS;
#elif BUILDFLAG(IS_LINUX)
PlatformThread;
#else
using PlatformThread = PlatformThreadBase;
#endif
namespace internal {
void SetCurrentThreadType(ThreadType thread_type,
MessagePumpType pump_type_hint);
void SetCurrentThreadTypeImpl(ThreadType thread_type,
MessagePumpType pump_type_hint);
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void SetThreadTypeLinux(PlatformThreadId process_id,
PlatformThreadId thread_id,
ThreadType thread_type,
IsViaIPC via_ipc);
#endif
#if BUILDFLAG(IS_CHROMEOS)
void SetThreadTypeChromeOS(PlatformThreadId process_id,
PlatformThreadId thread_id,
ThreadType thread_type,
IsViaIPC via_ipc);
#endif
#if BUILDFLAG(IS_CHROMEOS)
inline constexpr auto SetThreadType = SetThreadTypeChromeOS;
#elif BUILDFLAG(IS_LINUX)
inline constexpr auto SetThreadType = …;
#endif
}
}
#endif