diff options
| -rw-r--r-- | libc/bionic/fork.c | 4 | ||||
| -rw-r--r-- | libc/bionic/pthread-atfork.c | 5 | ||||
| -rw-r--r-- | libc/bionic/pthread.c | 11 | ||||
| -rw-r--r-- | libc/private/bionic_pthread.h | 1 |
4 files changed, 20 insertions, 1 deletions
diff --git a/libc/bionic/fork.c b/libc/bionic/fork.c index 0eedb0119..2d5a10a8d 100644 --- a/libc/bionic/fork.c +++ b/libc/bionic/fork.c @@ -27,6 +27,7 @@ */ #include <unistd.h> #include "pthread_internal.h" +#include "bionic_pthread.h" #include "cpuacct.h" extern int __fork(void); @@ -48,6 +49,9 @@ int fork(void) __timer_table_start_stop(0); __bionic_atfork_run_parent(); } else { + /* Adjusting the kernel id after a fork */ + (void)__pthread_settid(pthread_self(), gettid()); + /* * Newly created process must update cpu accounting. * Call cpuacct_add passing in our uid, which will take diff --git a/libc/bionic/pthread-atfork.c b/libc/bionic/pthread-atfork.c index 3a5189d8c..42420dc4c 100644 --- a/libc/bionic/pthread-atfork.c +++ b/libc/bionic/pthread-atfork.c @@ -74,6 +74,7 @@ void __bionic_atfork_run_prepare() void __bionic_atfork_run_child() { struct atfork_t *cursor; + pthread_mutexattr_t attr; /* Call pthread_atfork() child handlers */ for (cursor = atfork_head.cqh_first; @@ -84,7 +85,9 @@ void __bionic_atfork_run_child() } } - pthread_mutex_unlock(&handler_mutex); + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&handler_mutex, &attr); } void __bionic_atfork_run_parent() diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c index d9ca4322c..fdfe50856 100644 --- a/libc/bionic/pthread.c +++ b/libc/bionic/pthread.c @@ -2292,3 +2292,14 @@ pid_t __pthread_gettid(pthread_t thid) pthread_internal_t* thread = (pthread_internal_t*)thid; return thread->kernel_id; } + +int __pthread_settid(pthread_t thid, pid_t tid) +{ + if (thid == 0) + return EINVAL; + + pthread_internal_t* thread = (pthread_internal_t*)thid; + thread->kernel_id = tid; + + return 0; +} diff --git a/libc/private/bionic_pthread.h b/libc/private/bionic_pthread.h index 07bcbd4b0..28d6ad83e 100644 --- a/libc/private/bionic_pthread.h +++ b/libc/private/bionic_pthread.h @@ -35,6 +35,7 @@ __BEGIN_DECLS /* Internal, not an NDK API */ extern pid_t __pthread_gettid(pthread_t thid); +extern int __pthread_settid(pthread_t thid, pid_t tid); __END_DECLS |
