| Josh Gao | 5791e21 | 2018-03-16 14:25:42 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2018 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 <android-base/threads.h> | 
|  | 18 |  | 
|  | 19 | #include <stdint.h> | 
|  | 20 | #include <unistd.h> | 
|  | 21 |  | 
|  | 22 | #if defined(__APPLE__) | 
|  | 23 | #include <pthread.h> | 
|  | 24 | #elif defined(__linux__) && !defined(__ANDROID__) | 
|  | 25 | #include <syscall.h> | 
|  | 26 | #elif defined(_WIN32) | 
|  | 27 | #include <windows.h> | 
|  | 28 | #endif | 
|  | 29 |  | 
|  | 30 | namespace android { | 
|  | 31 | namespace base { | 
|  | 32 |  | 
|  | 33 | uint64_t GetThreadId() { | 
|  | 34 | #if defined(__BIONIC__) | 
|  | 35 | return gettid(); | 
|  | 36 | #elif defined(__APPLE__) | 
|  | 37 | uint64_t tid; | 
|  | 38 | pthread_threadid_np(NULL, &tid); | 
|  | 39 | return tid; | 
|  | 40 | #elif defined(__linux__) | 
|  | 41 | return syscall(__NR_gettid); | 
|  | 42 | #elif defined(_WIN32) | 
|  | 43 | return GetCurrentThreadId(); | 
|  | 44 | #endif | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | }  // namespace base | 
|  | 48 | }  // namespace android | 
| Elliott Hughes | 3848890 | 2018-07-11 11:13:16 -0700 | [diff] [blame] | 49 |  | 
|  | 50 | #if defined(__GLIBC__) | 
|  | 51 | int tgkill(int tgid, int tid, int sig) { | 
|  | 52 | return syscall(__NR_tgkill, tgid, tid, sig); | 
|  | 53 | } | 
|  | 54 | #endif |