Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 1 | /* |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 2 | ** Copyright (C) 2007, The Android Open Source Project |
| 3 | ** |
Yabin Cui | 4a6e5a3 | 2015-01-26 19:48:54 -0800 | [diff] [blame] | 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 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 7 | ** |
Yabin Cui | 4a6e5a3 | 2015-01-26 19:48:54 -0800 | [diff] [blame] | 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 9 | ** |
Yabin Cui | 4a6e5a3 | 2015-01-26 19:48:54 -0800 | [diff] [blame] | 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 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 14 | ** limitations under the License. |
| 15 | */ |
Mark Salyzyn | 1271716 | 2014-04-29 15:49:14 -0700 | [diff] [blame] | 16 | |
Elliott Hughes | 8e9aeb9 | 2017-11-10 10:22:07 -0800 | [diff] [blame] | 17 | #include <cutils/threads.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 18 | |
Dan Albert | 7dfb61d | 2015-03-20 13:46:28 -0700 | [diff] [blame] | 19 | #if defined(__APPLE__) |
Christopher Ferris | fc3576f | 2015-03-23 21:35:56 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
Elliott Hughes | dcf8184 | 2020-12-07 10:54:53 -0800 | [diff] [blame] | 21 | #elif defined(__linux__) |
Dan Albert | 7dfb61d | 2015-03-20 13:46:28 -0700 | [diff] [blame] | 22 | #include <syscall.h> |
| 23 | #include <unistd.h> |
| 24 | #elif defined(_WIN32) |
Dan Albert | b3a36ca | 2015-04-29 17:13:32 -0700 | [diff] [blame] | 25 | #include <windows.h> |
Dan Albert | 7dfb61d | 2015-03-20 13:46:28 -0700 | [diff] [blame] | 26 | #endif |
| 27 | |
Adrian Ratiu | a742158 | 2021-03-01 20:04:37 +0200 | [diff] [blame] | 28 | #if defined(__BIONIC__) || defined(__GLIBC__) && __GLIBC_MINOR__ >= 32 |
Dan Albert | b3a36ca | 2015-04-29 17:13:32 -0700 | [diff] [blame] | 29 | // No definition needed for Android because we'll just pick up bionic's copy. |
Adrian Ratiu | a742158 | 2021-03-01 20:04:37 +0200 | [diff] [blame] | 30 | // No definition needed for Glibc >= 2.32 because it exposes its own copy. |
Elliott Hughes | dcf8184 | 2020-12-07 10:54:53 -0800 | [diff] [blame] | 31 | #else |
Dan Albert | b3a36ca | 2015-04-29 17:13:32 -0700 | [diff] [blame] | 32 | pid_t gettid() { |
| 33 | #if defined(__APPLE__) |
Christopher N. Hesse | 684b442 | 2016-09-17 18:29:03 +0200 | [diff] [blame] | 34 | uint64_t tid; |
| 35 | pthread_threadid_np(NULL, &tid); |
| 36 | return tid; |
Dan Albert | b3a36ca | 2015-04-29 17:13:32 -0700 | [diff] [blame] | 37 | #elif defined(__linux__) |
| 38 | return syscall(__NR_gettid); |
| 39 | #elif defined(_WIN32) |
| 40 | return GetCurrentThreadId(); |
| 41 | #endif |
| 42 | } |
Elliott Hughes | 0675702 | 2020-12-02 11:21:14 -0800 | [diff] [blame] | 43 | #endif |