From 75ef63d6cf83787233d1c45489c4ec03b0a67d16 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Fri, 21 Nov 2014 00:18:07 -0800 Subject: [PATCH] Move some pthread functions to signal.h. POSIX specifies that pthread_kill(3) and pthread_sigmask(3) are supposed to live in signal.h rather than pthread.h. Since signal.h now needs pthread_t and pthread_attr_t, I've moved those defintions into include/machine/pthread_types.h to keep the namespace clean. I also sorted some includes. The combination of these two things seems to have exploded into a cascade of missing includes, so this patch also cleans up all those. Change-Id: Icfa92a39432fe83f542a797e5a113289d7e4ad0c --- libc/bionic/locale.cpp | 1 + libc/bionic/mntent.cpp | 1 + libc/bionic/pthread_atfork.cpp | 1 + libc/bionic/pthread_internals.cpp | 2 ++ libc/bionic/pthread_key.cpp | 1 + libc/bionic/raise.cpp | 1 + libc/include/machine/pthread_types.h | 48 ++++++++++++++++++++++++++++ libc/include/pthread.h | 24 +++----------- libc/include/signal.h | 14 +++++--- libc/private/kernel_sigset_t.h | 2 ++ 10 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 libc/include/machine/pthread_types.h diff --git a/libc/bionic/locale.cpp b/libc/bionic/locale.cpp index 681e03836..90aa7b8aa 100644 --- a/libc/bionic/locale.cpp +++ b/libc/bionic/locale.cpp @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ +#include #include #include #include diff --git a/libc/bionic/mntent.cpp b/libc/bionic/mntent.cpp index f5a8eaa25..4afacda60 100644 --- a/libc/bionic/mntent.cpp +++ b/libc/bionic/mntent.cpp @@ -27,6 +27,7 @@ */ #include +#include #include "private/ThreadLocalBuffer.h" diff --git a/libc/bionic/pthread_atfork.cpp b/libc/bionic/pthread_atfork.cpp index b845f7def..82e2b595d 100644 --- a/libc/bionic/pthread_atfork.cpp +++ b/libc/bionic/pthread_atfork.cpp @@ -28,6 +28,7 @@ #include #include +#include struct atfork_t { atfork_t* next; diff --git a/libc/bionic/pthread_internals.cpp b/libc/bionic/pthread_internals.cpp index 19c00d47c..2270d96f3 100644 --- a/libc/bionic/pthread_internals.cpp +++ b/libc/bionic/pthread_internals.cpp @@ -28,6 +28,8 @@ #include "pthread_internal.h" +#include + #include "private/bionic_futex.h" #include "private/bionic_tls.h" #include "private/ScopedPthreadMutexLocker.h" diff --git a/libc/bionic/pthread_key.cpp b/libc/bionic/pthread_key.cpp index 27eab2706..b47ef229d 100644 --- a/libc/bionic/pthread_key.cpp +++ b/libc/bionic/pthread_key.cpp @@ -26,6 +26,7 @@ * SUCH DAMAGE. */ +#include #include #include "private/bionic_tls.h" diff --git a/libc/bionic/raise.cpp b/libc/bionic/raise.cpp index f69d90b60..0dd0ad7b8 100644 --- a/libc/bionic/raise.cpp +++ b/libc/bionic/raise.cpp @@ -27,6 +27,7 @@ */ #include +#include int raise(int sig) { int rc = pthread_kill(pthread_self(), sig); diff --git a/libc/include/machine/pthread_types.h b/libc/include/machine/pthread_types.h new file mode 100644 index 000000000..900541c15 --- /dev/null +++ b/libc/include/machine/pthread_types.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2008 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. + */ + +#ifndef _MACHINE_PTHREAD_TYPES_H_ +#define _MACHINE_PTHREAD_TYPES_H_ + +#include + +typedef long pthread_t; + +typedef struct { + uint32_t flags; + void* stack_base; + size_t stack_size; + size_t guard_size; + int32_t sched_policy; + int32_t sched_priority; +#ifdef __LP64__ + char __reserved[16]; +#endif +} pthread_attr_t; + +#endif /* _MACHINE_PTHREAD_TYPES_H_ */ diff --git a/libc/include/pthread.h b/libc/include/pthread.h index 86a10051e..24dba1bcf 100644 --- a/libc/include/pthread.h +++ b/libc/include/pthread.h @@ -29,11 +29,12 @@ #ifndef _PTHREAD_H_ #define _PTHREAD_H_ -#include -#include -#include #include +#include +#include +#include #include +#include #if defined(__LP64__) #define __RESERVED_INITIALIZER , {0} @@ -76,18 +77,6 @@ typedef struct { #define PTHREAD_COND_INITIALIZER {0 __RESERVED_INITIALIZER} -typedef struct { - uint32_t flags; - void* stack_base; - size_t stack_size; - size_t guard_size; - int32_t sched_policy; - int32_t sched_priority; -#ifdef __LP64__ - char __reserved[16]; -#endif -} pthread_attr_t; - typedef long pthread_mutexattr_t; typedef long pthread_condattr_t; @@ -118,7 +107,6 @@ typedef struct { #endif typedef int pthread_key_t; -typedef long pthread_t; typedef volatile int pthread_once_t; @@ -195,8 +183,6 @@ int pthread_join(pthread_t, void**); int pthread_key_create(pthread_key_t*, void (*)(void*)) __nonnull((1)); int pthread_key_delete(pthread_key_t); -int pthread_kill(pthread_t, int); - int pthread_mutexattr_destroy(pthread_mutexattr_t*) __nonnull((1)); int pthread_mutexattr_getpshared(const pthread_mutexattr_t*, int*) __nonnull((1, 2)); int pthread_mutexattr_gettype(const pthread_mutexattr_t*, int*) __nonnull((1, 2)); @@ -236,8 +222,6 @@ int pthread_setschedparam(pthread_t, int, const struct sched_param*) __nonnull(( int pthread_setspecific(pthread_key_t, const void*); -int pthread_sigmask(int, const sigset_t*, sigset_t*); - typedef void (*__pthread_cleanup_func_t)(void*); typedef struct __pthread_cleanup_t { diff --git a/libc/include/signal.h b/libc/include/signal.h index e23e65b80..6d89ef7d0 100644 --- a/libc/include/signal.h +++ b/libc/include/signal.h @@ -29,12 +29,13 @@ #ifndef _SIGNAL_H_ #define _SIGNAL_H_ -#include -#include -#include /* For LONG_BIT */ -#include /* For memset() */ -#include #include +#include +#include +#include +#include +#include +#include #if defined(__LP64__) || defined(__mips__) /* For 64-bit (and mips), the kernel's struct sigaction doesn't match the POSIX one, @@ -129,6 +130,9 @@ extern int sigaltstack(const stack_t*, stack_t*); extern void psiginfo(const siginfo_t*, const char*); extern void psignal(int, const char*); +extern int pthread_kill(pthread_t, int); +extern int pthread_sigmask(int, const sigset_t*, sigset_t*); + __END_DECLS #endif /* _SIGNAL_H_ */ diff --git a/libc/private/kernel_sigset_t.h b/libc/private/kernel_sigset_t.h index b2d6386f3..9415fcf5d 100644 --- a/libc/private/kernel_sigset_t.h +++ b/libc/private/kernel_sigset_t.h @@ -17,6 +17,8 @@ #ifndef LIBC_PRIVATE_KERNEL_SIGSET_T_H_ #define LIBC_PRIVATE_KERNEL_SIGSET_T_H_ +#include + // Our sigset_t is wrong for ARM and x86. It's 32-bit but the kernel expects 64 bits. // This means we can't support real-time signals correctly until we can change the ABI. // In the meantime, we can use this union to pass an appropriately-sized block of memory