diff --git a/libc/Android.mk b/libc/Android.mk index 80abce76e..ce75e0d86 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -158,6 +158,7 @@ libc_bionic_src_files := \ bionic/pthread_exit.cpp \ bionic/pthread_getcpuclockid.cpp \ bionic/pthread_getschedparam.cpp \ + bionic/pthread_gettid_np.cpp \ bionic/pthread_internals.cpp \ bionic/pthread_join.cpp \ bionic/pthread_key.cpp \ diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp index 312bf9e59..7ad0ef1fb 100644 --- a/libc/bionic/posix_timers.cpp +++ b/libc/bionic/posix_timers.cpp @@ -28,7 +28,6 @@ #include "pthread_internal.h" #include "private/bionic_futex.h" -#include "private/bionic_pthread.h" #include "private/kernel_sigset_t.h" #include @@ -159,7 +158,7 @@ int timer_create(clockid_t clock_id, sigevent* evp, timer_t* timer_id) { sigevent se = *evp; se.sigev_signo = TIMER_SIGNAL; se.sigev_notify = SIGEV_THREAD_ID; - se.sigev_notify_thread_id = __pthread_gettid(timer->callback_thread); + se.sigev_notify_thread_id = pthread_gettid_np(timer->callback_thread); if (__timer_create(clock_id, &se, &timer->kernel_timer_id) == -1) { __timer_thread_stop(timer); return -1; diff --git a/libc/bionic/pthread_gettid_np.cpp b/libc/bionic/pthread_gettid_np.cpp new file mode 100644 index 000000000..f4663a739 --- /dev/null +++ b/libc/bionic/pthread_gettid_np.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "pthread_internal.h" +#include "private/bionic_pthread.h" + +pid_t pthread_gettid_np(pthread_t t) { + return reinterpret_cast(t)->tid; +} + +// TODO: move callers over to pthread_gettid_np and remove this. +pid_t __pthread_gettid(pthread_t t) { + return pthread_gettid_np(t); +} diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h index 7bcd758d1..a5b300220 100644 --- a/libc/bionic/pthread_internal.h +++ b/libc/bionic/pthread_internal.h @@ -98,7 +98,9 @@ __LIBC_HIDDEN__ int __init_thread(pthread_internal_t* thread, bool add_to_thread __LIBC_HIDDEN__ void __init_tls(pthread_internal_t* thread); __LIBC_HIDDEN__ void __init_alternate_signal_stack(pthread_internal_t*); __LIBC_HIDDEN__ void _pthread_internal_add(pthread_internal_t* thread); -__LIBC_HIDDEN__ pthread_internal_t* __get_thread(void); + +/* Various third-party apps contain a backport of our pthread_rwlock implementation that uses this. */ +extern "C" __LIBC64_HIDDEN__ pthread_internal_t* __get_thread(void); __LIBC_HIDDEN__ void pthread_key_clean_all(void); __LIBC_HIDDEN__ void _pthread_internal_remove_locked(pthread_internal_t* thread); diff --git a/libc/bionic/pthread_internals.cpp b/libc/bionic/pthread_internals.cpp index 8c5d9c7e9..4c08ba87b 100644 --- a/libc/bionic/pthread_internals.cpp +++ b/libc/bionic/pthread_internals.cpp @@ -29,7 +29,6 @@ #include "pthread_internal.h" #include "private/bionic_futex.h" -#include "private/bionic_pthread.h" #include "private/bionic_tls.h" #include "private/ScopedPthreadMutexLocker.h" @@ -69,10 +68,6 @@ pthread_internal_t* __get_thread(void) { return reinterpret_cast(__get_tls()[TLS_SLOT_THREAD_ID]); } -pid_t __pthread_gettid(pthread_t t) { - return reinterpret_cast(t)->tid; -} - // Initialize 'ts' with the difference between 'abstime' and the current time // according to 'clock'. Returns -1 if abstime already expired, or 0 otherwise. int __timespec_from_absolute(timespec* ts, const timespec* abstime, clockid_t clock) { diff --git a/libc/include/pthread.h b/libc/include/pthread.h index 29caafc6d..86a10051e 100644 --- a/libc/include/pthread.h +++ b/libc/include/pthread.h @@ -188,6 +188,8 @@ int pthread_getschedparam(pthread_t, int*, struct sched_param*) __nonnull((2, 3) void* pthread_getspecific(pthread_key_t); +pid_t pthread_gettid_np(pthread_t); + int pthread_join(pthread_t, void**); int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1));