diff options
Diffstat (limited to 'libpthread')
-rw-r--r-- | libpthread/linuxthreads.old/ptfork.c | 50 | ||||
-rw-r--r-- | libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h | 38 |
2 files changed, 80 insertions, 8 deletions
diff --git a/libpthread/linuxthreads.old/ptfork.c b/libpthread/linuxthreads.old/ptfork.c index c34ea8104..7a5749efc 100644 --- a/libpthread/linuxthreads.old/ptfork.c +++ b/libpthread/linuxthreads.old/ptfork.c @@ -20,6 +20,7 @@ #ifdef __ARCH_USE_MMU__ +#include <bits/uClibc_mutex.h> #include <stddef.h> #include <stdlib.h> #include <unistd.h> @@ -36,6 +37,16 @@ static struct handler_list * pthread_atfork_prepare = NULL; static struct handler_list * pthread_atfork_parent = NULL; static struct handler_list * pthread_atfork_child = NULL; +#ifdef __MALLOC__ +__UCLIBC_MUTEX_EXTERN(__malloc_heap_lock); +__UCLIBC_MUTEX_EXTERN(__malloc_sbrk_lock); +#ifdef __UCLIBC_UCLINUX_BROKEN_MUNMAP__ +__UCLIBC_MUTEX_EXTERN(__malloc_mmb_heap_lock); +#endif +#elif defined(__MALLOC_STANDARD__) || defined(__MALLOC_SIMPLE__) +__UCLIBC_MUTEX_EXTERN(__malloc_lock); +#endif + static void pthread_insert_list(struct handler_list ** list, void (*handler)(void), struct handler_list * newlist, @@ -78,6 +89,10 @@ static __inline__ void pthread_call_handlers(struct handler_list * list) for (/*nothing*/; list != NULL; list = list->next) (list->handler)(); } +void __pthread_once_fork_prepare(void); +void __pthread_once_fork_child(void); +void __pthread_once_fork_parent(void); + extern __typeof(fork) __libc_fork; pid_t __fork(void) attribute_hidden; @@ -90,14 +105,47 @@ pid_t __fork(void) prepare = pthread_atfork_prepare; child = pthread_atfork_child; parent = pthread_atfork_parent; - __pthread_mutex_unlock(&pthread_atfork_lock); pthread_call_handlers(prepare); + + __pthread_once_fork_prepare(); +#ifdef __MALLOC__ + __pthread_mutex_lock(&__malloc_sbrk_lock); + __pthread_mutex_lock(&__malloc_heap_lock); +#ifdef __UCLIBC_UCLINUX_BROKEN_MUNMAP__ + __pthread_mutex_lock(&__malloc_mmb_heap_lock); +#endif +#elif defined(__MALLOC_STANDARD__) || defined(__MALLOC_SIMPLE__) + __pthread_mutex_lock(&__malloc_lock); +#endif + pid = __libc_fork(); if (pid == 0) { +#if defined(__MALLOC_STANDARD__) || defined(__MALLOC_SIMPLE__) + __libc_lock_init_recursive(__malloc_lock); +#elif defined(__MALLOC__) +#ifdef __UCLIBC_UCLINUX_BROKEN_MUNMAP__ + __libc_lock_init_adaptive(__malloc_mmb_heap_lock); +#endif + __libc_lock_init_adaptive(__malloc_heap_lock); + __libc_lock_init(__malloc_sbrk_lock); +#endif + __libc_lock_init_adaptive(pthread_atfork_lock); __pthread_reset_main_thread(); __fresetlockfiles(); + __pthread_once_fork_child(); pthread_call_handlers(child); } else { +#if defined(__MALLOC_STANDARD__) || defined(__MALLOC_SIMPLE__) + __pthread_mutex_unlock(&__malloc_lock); +#elif defined(__MALLOC__) +#ifdef __UCLIBC_UCLINUX_BROKEN_MUNMAP__ + __pthread_mutex_unlock(&__malloc_mmb_heap_lock); +#endif + __pthread_mutex_unlock(&__malloc_heap_lock); + __pthread_mutex_unlock(&__malloc_sbrk_lock); +#endif + __pthread_mutex_unlock(&pthread_atfork_lock); + __pthread_once_fork_parent(); pthread_call_handlers(parent); } return pid; diff --git a/libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h b/libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h index 740e793be..78593ac11 100644 --- a/libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h +++ b/libpthread/linuxthreads.old/sysdeps/pthread/bits/libc-lock.h @@ -30,7 +30,7 @@ /* Mutex type. */ #if defined(_LIBC) || defined(_IO_MTSAFE_IO) typedef pthread_mutex_t __libc_lock_t; -typedef struct { pthread_mutex_t mutex; } __libc_lock_recursive_t; +typedef pthread_mutex_t __libc_lock_recursive_t; # ifdef __USE_UNIX98 typedef pthread_rwlock_t __libc_rwlock_t; # else @@ -132,15 +132,39 @@ typedef pthread_key_t __libc_key_t; #define __libc_rwlock_init(NAME) \ (__libc_maybe_call (__pthread_rwlock_init, (&(NAME), NULL), 0)); +/* Same as last but this time we initialize an adaptive mutex. */ +#if defined _LIBC && !defined NOT_IN_libc && defined SHARED +#define __libc_lock_init_adaptive(NAME) \ + ({ \ + (NAME).__m_count = 0; \ + (NAME).__m_owner = NULL; \ + (NAME).__m_kind = PTHREAD_MUTEX_ADAPTIVE_NP; \ + (NAME).__m_lock.__status = 0; \ + (NAME).__m_lock.__spinlock = __LT_SPINLOCK_INIT; \ + 0; }) +#else +#define __libc_lock_init_adaptive(NAME) \ + do { \ + if (__pthread_mutex_init != NULL) \ + { \ + pthread_mutexattr_t __attr; \ + __pthread_mutexattr_init (&__attr); \ + __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_ADAPTIVE_NP); \ + __pthread_mutex_init (&(NAME), &__attr); \ + __pthread_mutexattr_destroy (&__attr); \ + } \ + } while (0); +#endif + /* Same as last but this time we initialize a recursive mutex. */ #if defined _LIBC && !defined NOT_IN_libc && defined SHARED #define __libc_lock_init_recursive(NAME) \ ({ \ - (NAME).mutex.__m_count = 0; \ - (NAME).mutex.__m_owner = NULL; \ - (NAME).mutex.__m_kind = PTHREAD_MUTEX_RECURSIVE_NP; \ - (NAME).mutex.__m_lock.__status = 0; \ - (NAME).mutex.__m_lock.__spinlock = __LT_SPINLOCK_INIT; \ + (NAME).__m_count = 0; \ + (NAME).__m_owner = NULL; \ + (NAME).__m_kind = PTHREAD_MUTEX_RECURSIVE_NP; \ + (NAME).__m_lock.__status = 0; \ + (NAME).__m_lock.__spinlock = __LT_SPINLOCK_INIT; \ 0; }) #else #define __libc_lock_init_recursive(NAME) \ @@ -150,7 +174,7 @@ typedef pthread_key_t __libc_key_t; pthread_mutexattr_t __attr; \ __pthread_mutexattr_init (&__attr); \ __pthread_mutexattr_settype (&__attr, PTHREAD_MUTEX_RECURSIVE_NP); \ - __pthread_mutex_init (&(NAME).mutex, &__attr); \ + __pthread_mutex_init (&(NAME), &__attr); \ __pthread_mutexattr_destroy (&__attr); \ } \ } while (0); |