#include "base/profiler/sampling_profiler_thread_token.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_OHOS)
#include <pthread.h>
#include "base/profiler/stack_base_address_posix.h"
#endif
namespace base {
SamplingProfilerThreadToken GetSamplingProfilerCurrentThreadToken() {
PlatformThreadId id = PlatformThread::CurrentId();
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE)
return {id, pthread_self()};
#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_OHOS)
std::optional<uintptr_t> maybe_stack_base =
GetThreadStackBaseAddress(id, pthread_self());
return {id, maybe_stack_base};
#else
return {id};
#endif
}
}