blob: 6ece7a3afc93c9567b46b33a5ab2f309f4ed7634 [file] [log] [blame]
Mark Salyzyn12717162014-04-29 15:49:14 -07001/*
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08002** Copyright (C) 2007, The Android Open Source Project
3**
Yabin Cui4a6e5a32015-01-26 19:48:54 -08004** 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
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08007**
Yabin Cui4a6e5a32015-01-26 19:48:54 -08008** http://www.apache.org/licenses/LICENSE-2.0
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08009**
Yabin Cui4a6e5a32015-01-26 19:48:54 -080010** 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
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080014** limitations under the License.
15*/
Mark Salyzyn12717162014-04-29 15:49:14 -070016
Elliott Hughes8e9aeb92017-11-10 10:22:07 -080017#include <cutils/threads.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080018
Dan Albert7dfb61d2015-03-20 13:46:28 -070019#if defined(__APPLE__)
Christopher Ferrisfc3576f2015-03-23 21:35:56 -070020#include <stdint.h>
Elliott Hughesdcf81842020-12-07 10:54:53 -080021#elif defined(__linux__)
Dan Albert7dfb61d2015-03-20 13:46:28 -070022#include <syscall.h>
23#include <unistd.h>
24#elif defined(_WIN32)
Dan Albertb3a36ca2015-04-29 17:13:32 -070025#include <windows.h>
Dan Albert7dfb61d2015-03-20 13:46:28 -070026#endif
27
Adrian Ratiua7421582021-03-01 20:04:37 +020028#if defined(__BIONIC__) || defined(__GLIBC__) && __GLIBC_MINOR__ >= 32
Dan Albertb3a36ca2015-04-29 17:13:32 -070029// No definition needed for Android because we'll just pick up bionic's copy.
Adrian Ratiua7421582021-03-01 20:04:37 +020030// No definition needed for Glibc >= 2.32 because it exposes its own copy.
Elliott Hughesdcf81842020-12-07 10:54:53 -080031#else
Dan Albertb3a36ca2015-04-29 17:13:32 -070032pid_t gettid() {
33#if defined(__APPLE__)
Christopher N. Hesse684b4422016-09-17 18:29:03 +020034 uint64_t tid;
35 pthread_threadid_np(NULL, &tid);
36 return tid;
Dan Albertb3a36ca2015-04-29 17:13:32 -070037#elif defined(__linux__)
38 return syscall(__NR_gettid);
39#elif defined(_WIN32)
40 return GetCurrentThreadId();
41#endif
42}
Elliott Hughes06757022020-12-02 11:21:14 -080043#endif