17fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris/* 27fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * Copyright (C) 2013 The Android Open Source Project 37fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * 47fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * Licensed under the Apache License, Version 2.0 (the "License"); 57fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * you may not use this file except in compliance with the License. 67fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * You may obtain a copy of the License at 77fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * 87fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * http://www.apache.org/licenses/LICENSE-2.0 97fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * 107fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * Unless required by applicable law or agreed to in writing, software 117fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * distributed under the License is distributed on an "AS IS" BASIS, 127fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * See the License for the specific language governing permissions and 147fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris * limitations under the License. 157fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris */ 167fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris 1717e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris#include "thread_utils.h" 187fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris 1917e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris#if defined(__APPLE__) 207fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris 2117e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris#include <sys/syscall.h> 227fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris 2317e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris// Mac OS >= 10.6 has a system call equivalent to Linux's gettid(). 2417e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferrispid_t gettid() { 2517e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris return syscall(SYS_thread_selfid); 267fb22878d43bddd48b854f8e201afb800393482aChristopher Ferris} 2717e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris 2817e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris#elif !defined(__BIONIC__) 2917e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris 3017e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris// glibc doesn't implement or export either gettid or tgkill. 3117e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris#include <unistd.h> 3217e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris#include <sys/syscall.h> 3317e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris 3417e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferrispid_t gettid() { 3517e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris return syscall(__NR_gettid); 3617e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris} 3717e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris 3817e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferrisint tgkill(int tgid, int tid, int sig) { 3917e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris return syscall(__NR_tgkill, tgid, tid, sig); 4017e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris} 4117e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris 4217e91d44edf5e6476a477a200bcd89d4327358a3Christopher Ferris#endif 43