Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libpthread Revert "Enhance the pthread(3) + malloc(3) in...



details:   https://anonhg.NetBSD.org/src/rev/5be8cabf7d5d
branches:  trunk
changeset: 744907:5be8cabf7d5d
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sun Feb 16 17:45:11 2020 +0000

description:
Revert "Enhance the pthread(3) + malloc(3) init model"

It is reported to hand on aarch64 with gzip.

diffstat:

 lib/libpthread/pthread.c       |  24 +++++-------------------
 lib/libpthread/pthread_int.h   |   5 ++---
 lib/libpthread/pthread_mutex.c |   9 ++++++---
 lib/libpthread/pthread_tsd.c   |  39 +++++++++++++++++----------------------
 4 files changed, 30 insertions(+), 47 deletions(-)

diffs (190 lines):

diff -r 015b410ef014 -r 5be8cabf7d5d lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c  Sun Feb 16 17:14:31 2020 +0000
+++ b/lib/libpthread/pthread.c  Sun Feb 16 17:45:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread.c,v 1.166 2020/02/16 17:14:31 kamil Exp $      */
+/*     $NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $      */
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.166 2020/02/16 17:14:31 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $");
 
 #define        __EXPOSE_STACK  1
 
@@ -181,7 +181,7 @@
         * while pthread_keys descriptors are not
         * yet allocated.
         */
-       pthread__main = pthread_tsd_earlyinit(&__pthread_st_size);
+       pthread__main = pthread_tsd_init(&__pthread_st_size);
        if (pthread__main == NULL)
                err(EXIT_FAILURE, "Cannot allocate pthread storage");
 
@@ -257,23 +257,9 @@
                }
        }
 
-       /*
-        * We are officially threded now.
-        *
-        * libc must be informed about this before bootstrapping malloc(3).
-        */
+       /* Tell libc that we're here and it should role-play accordingly. */
+       pthread_atfork(NULL, NULL, pthread__fork_callback);
        __isthreaded = 1;
-
-       /*
-        * Tell libc that we're here and it should role-play accordingly.
-        *
-        * pthread_atfork(3) calls malloc(3) and initializes the system malloc.
-        * At this point all POSIX thread inferfaces must be functional.
-        */
-       pthread_atfork(NULL, NULL, pthread__fork_callback);
-
-       /* Register atfork handlers for TSD. */
-       pthread_tsd_init();
 }
 
 static void
diff -r 015b410ef014 -r 5be8cabf7d5d lib/libpthread/pthread_int.h
--- a/lib/libpthread/pthread_int.h      Sun Feb 16 17:14:31 2020 +0000
+++ b/lib/libpthread/pthread_int.h      Sun Feb 16 17:45:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_int.h,v 1.102 2020/02/15 23:59:30 kamil Exp $  */
+/*     $NetBSD: pthread_int.h,v 1.103 2020/02/16 17:45:11 kamil Exp $  */
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -294,8 +294,7 @@
        }                                                               \
         } while (/*CONSTCOND*/0)
 
-void   *pthread_tsd_earlyinit(size_t *) PTHREAD_HIDE;
-void   pthread_tsd_init(void) PTHREAD_HIDE;
+void   *pthread_tsd_init(size_t *) PTHREAD_HIDE;
 void   pthread__destroy_tsd(pthread_t) PTHREAD_HIDE;
 void   pthread__copy_tsd(pthread_t) PTHREAD_HIDE;
 
diff -r 015b410ef014 -r 5be8cabf7d5d lib/libpthread/pthread_mutex.c
--- a/lib/libpthread/pthread_mutex.c    Sun Feb 16 17:14:31 2020 +0000
+++ b/lib/libpthread/pthread_mutex.c    Sun Feb 16 17:45:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_mutex.c,v 1.75 2020/02/15 23:59:30 kamil Exp $ */
+/*     $NetBSD: pthread_mutex.c,v 1.76 2020/02/16 17:45:11 kamil Exp $ */
 
 /*-
  * Copyright (c) 2001, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_mutex.c,v 1.75 2020/02/15 23:59:30 kamil Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.76 2020/02/16 17:45:11 kamil Exp $");
 
 #include <sys/types.h>
 #include <sys/lwpctl.h>
@@ -122,12 +122,14 @@
 {
        uintptr_t type, proto, val, ceil;
 
+#if 0
        /*
         * Always initialize the mutex structure, maybe be used later
         * and the cost should be minimal.
         */
        if (__predict_false(__uselibcstub))
                return __libc_mutex_init_stub(ptm, attr);
+#endif
 
        pthread__error(EINVAL, "Invalid mutes attribute",
            attr == NULL || attr->ptma_magic == _PT_MUTEXATTR_MAGIC);
@@ -617,9 +619,10 @@
 int
 pthread_mutexattr_init(pthread_mutexattr_t *attr)
 {
-
+#if 0
        if (__predict_false(__uselibcstub))
                return __libc_mutexattr_init_stub(attr);
+#endif
 
        attr->ptma_magic = _PT_MUTEXATTR_MAGIC;
        attr->ptma_private = (void *)PTHREAD_MUTEX_DEFAULT;
diff -r 015b410ef014 -r 5be8cabf7d5d lib/libpthread/pthread_tsd.c
--- a/lib/libpthread/pthread_tsd.c      Sun Feb 16 17:14:31 2020 +0000
+++ b/lib/libpthread/pthread_tsd.c      Sun Feb 16 17:45:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_tsd.c,v 1.19 2020/02/15 23:59:30 kamil Exp $   */
+/*     $NetBSD: pthread_tsd.c,v 1.20 2020/02/16 17:45:11 kamil Exp $   */
 
 /*-
  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_tsd.c,v 1.19 2020/02/15 23:59:30 kamil Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.20 2020/02/16 17:45:11 kamil Exp $");
 
 /* Functions and structures dealing with thread-specific data */
 #include <errno.h>
@@ -61,13 +61,27 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+static void
+pthread_tsd_prefork(void)
+{
+       pthread_mutex_lock(&tsd_mutex);
+}
+
+static void
+pthread_tsd_postfork(void)
+{
+       pthread_mutex_unlock(&tsd_mutex);
+}
+
 void *
-pthread_tsd_earlyinit(size_t *tlen)
+pthread_tsd_init(size_t *tlen)
 {
        char *pkm;
        size_t alen;
        char *arena;
 
+       pthread_atfork(pthread_tsd_prefork, pthread_tsd_postfork, pthread_tsd_postfork);
+
        if ((pkm = pthread__getenv("PTHREAD_KEYS_MAX")) != NULL) {
                pthread_keys_max = (int)strtol(pkm, NULL, 0);
                if (pthread_keys_max < _POSIX_THREAD_KEYS_MAX)
@@ -99,25 +113,6 @@
        return arena;
 }
 
-static void
-pthread_tsd_prefork(void)
-{
-       pthread_mutex_lock(&tsd_mutex);
-}
-
-static void
-pthread_tsd_postfork(void)
-{
-       pthread_mutex_unlock(&tsd_mutex);
-}
-
-void
-pthread_tsd_init(void)
-{
-
-       pthread_atfork(pthread_tsd_prefork, pthread_tsd_postfork, pthread_tsd_postfork);
-}
-
 int
 pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
 {



Home | Main Index | Thread Index | Old Index