1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_PROFILER_SAMPLING_PROFILER_THREAD_TOKEN_H_
6 #define BASE_PROFILER_SAMPLING_PROFILER_THREAD_TOKEN_H_
8 #include "base/base_export.h"
9 #include "base/threading/platform_thread.h"
10 #include "build/build_config.h"
11 #include "third_party/abseil-cpp/absl/types/optional.h"
13 #if BUILDFLAG(IS_ANDROID)
15 #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
21 // SamplingProfilerThreadToken represents the thread identifier(s) required by
22 // sampling profiler to operate on a thread. PlatformThreadId is needed for all
23 // platforms, while Android also requires a pthread_t to pass to pthread
24 // functions used to obtain the stack base address.
25 struct SamplingProfilerThreadToken {
27 #if BUILDFLAG(IS_ANDROID)
29 #elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
30 // Due to the sandbox, we can only retrieve the stack base address for the
31 // current thread. We must grab it during
32 // GetSamplingProfilerCurrentThreadToken() and not try to get it later.
33 absl::optional<uintptr_t> stack_base_address;
37 BASE_EXPORT SamplingProfilerThreadToken GetSamplingProfilerCurrentThreadToken();
41 #endif // BASE_PROFILER_SAMPLING_PROFILER_THREAD_TOKEN_H_