• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "perfetto/base/thread_utils.h"
18 
19 #include "perfetto/base/build_config.h"
20 
21 #if PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA)
22 #include <zircon/process.h>
23 #include <zircon/syscalls.h>
24 #include <zircon/types.h>
25 #endif  // PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA)
26 
27 namespace perfetto {
28 namespace base {
29 
30 #if PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA)
ResolveThreadId()31 static PlatformThreadId ResolveThreadId() {
32   zx_info_handle_basic_t basic;
33   return (zx_object_get_info(zx_thread_self(), ZX_INFO_HANDLE_BASIC, &basic,
34                              sizeof(basic), nullptr, nullptr) == ZX_OK)
35              ? basic.koid
36              : ZX_KOID_INVALID;
37 }
GetThreadId()38 PlatformThreadId GetThreadId() {
39   thread_local static PlatformThreadId thread_id = ResolveThreadId();
40   return thread_id;
41 }
42 #endif  // PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA)
43 
44 }  // namespace base
45 }  // namespace perfetto
46