• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #ifndef INCLUDE_PERFETTO_PUBLIC_THREAD_UTILS_H_
18 #define INCLUDE_PERFETTO_PUBLIC_THREAD_UTILS_H_
19 
20 #include <stdlib.h>
21 
22 #include "perfetto/public/abi/thread_utils_abi.h"
23 #include "perfetto/public/compiler.h"
24 
25 #if defined(__BIONIC__)
26 
27 #include <unistd.h>
28 
PerfettoGetThreadId(void)29 static inline PerfettoThreadId PerfettoGetThreadId(void) {
30   return gettid();
31 }
32 #elif defined(__linux__)
33 
34 #include <sys/syscall.h>
35 #include <sys/types.h>
36 #include <unistd.h>
PerfettoGetThreadId(void)37 static inline PerfettoThreadId PerfettoGetThreadId(void) {
38   return PERFETTO_STATIC_CAST(PerfettoThreadId, syscall(__NR_gettid));
39 }
40 
41 #else
42 
PerfettoGetThreadId(void)43 static inline PerfettoThreadId PerfettoGetThreadId(void) {
44   return PerfettoGetThreadIdImpl();
45 }
46 
47 #endif
48 
49 #endif  // INCLUDE_PERFETTO_PUBLIC_THREAD_UTILS_H_
50