Module Name: src
Committed By: kamil
Date: Sun Feb 16 17:45:12 UTC 2020
Modified Files:
src/lib/libpthread: pthread.c pthread_int.h pthread_mutex.c
pthread_tsd.c
Log Message:
Revert "Enhance the pthread(3) + malloc(3) init model"
It is reported to hand on aarch64 with gzip.
To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/lib/libpthread/pthread.c
cvs rdiff -u -r1.102 -r1.103 src/lib/libpthread/pthread_int.h
cvs rdiff -u -r1.75 -r1.76 src/lib/libpthread/pthread_mutex.c
cvs rdiff -u -r1.19 -r1.20 src/lib/libpthread/pthread_tsd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libpthread/pthread.c
diff -u src/lib/libpthread/pthread.c:1.166 src/lib/libpthread/pthread.c:1.167
--- src/lib/libpthread/pthread.c:1.166 Sun Feb 16 17:14:31 2020
+++ src/lib/libpthread/pthread.c Sun Feb 16 17:45:11 2020
@@ -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 @@ pthread__init(void)
* 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 @@ pthread__init(void)
}
}
- /*
- * We are officially threded now.
- *
- * libc must be informed about this before bootstrapping malloc(3).
- */
- __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.
- */
+ /* Tell libc that we're here and it should role-play accordingly. */
pthread_atfork(NULL, NULL, pthread__fork_callback);
-
- /* Register atfork handlers for TSD. */
- pthread_tsd_init();
+ __isthreaded = 1;
}
static void
Index: src/lib/libpthread/pthread_int.h
diff -u src/lib/libpthread/pthread_int.h:1.102 src/lib/libpthread/pthread_int.h:1.103
--- src/lib/libpthread/pthread_int.h:1.102 Sat Feb 15 23:59:30 2020
+++ src/lib/libpthread/pthread_int.h Sun Feb 16 17:45:11 2020
@@ -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 @@ pthread__self(void)
} \
} 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;
Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.75 src/lib/libpthread/pthread_mutex.c:1.76
--- src/lib/libpthread/pthread_mutex.c:1.75 Sat Feb 15 23:59:30 2020
+++ src/lib/libpthread/pthread_mutex.c Sun Feb 16 17:45:11 2020
@@ -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 @@ pthread_mutex_init(pthread_mutex_t *ptm,
{
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 @@ pthread__mutex_wakeup(pthread_t self, pt
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;
Index: src/lib/libpthread/pthread_tsd.c
diff -u src/lib/libpthread/pthread_tsd.c:1.19 src/lib/libpthread/pthread_tsd.c:1.20
--- src/lib/libpthread/pthread_tsd.c:1.19 Sat Feb 15 23:59:30 2020
+++ src/lib/libpthread/pthread_tsd.c Sun Feb 16 17:45:11 2020
@@ -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 @@ null_destructor(void *p)
#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 @@ pthread_tsd_earlyinit(size_t *tlen)
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 *))
{