Source-Changes-HG archive

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

[src-draft/trunk]: src/lib/libpthread Lock/unlock/reinit pthread__deadqueue_l...



details:   https://anonhg.NetBSD.org/src-all/rev/d581bb3dc6df
branches:  trunk
changeset: 932670:d581bb3dc6df
user:      Joerg Sonnenberger <joerg%bec.de@localhost>
date:      Sun May 10 01:16:31 2020 +0200

description:
Lock/unlock/reinit pthread__deadqueue_lock over fork.

diffstat:

 lib/libpthread/pthread.c |  41 +++++++++++++++++++++++++++--------------
 1 files changed, 27 insertions(+), 14 deletions(-)

diffs (68 lines):

diff -r 8bf01c77d234 -r d581bb3dc6df lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c  Thu Apr 30 16:34:35 2020 +0200
+++ b/lib/libpthread/pthread.c  Sun May 10 01:16:31 2020 +0200
@@ -82,7 +82,6 @@
 static void    pthread__initthread(pthread_t);
 static void    pthread__scrubthread(pthread_t, char *, int);
 static void    pthread__initmain(pthread_t *);
-static void    pthread__fork_callback(void);
 static void    pthread__reap(pthread_t);
 
 void   pthread__init(void);
@@ -155,6 +154,32 @@
        char            pad[64];
 } hashlocks[NHASHLOCK] __aligned(64);
 
+static void
+pthread__prefork(void)
+{
+       pthread_mutex_lock(&pthread__deadqueue_lock);
+}
+
+static void
+pthread__fork_parent(void)
+{
+       pthread_mutex_unlock(&pthread__deadqueue_lock);
+}
+
+static void
+pthread__fork_child(void)
+{
+       struct __pthread_st *self = pthread__self();
+
+       pthread_mutex_init(&pthread__deadqueue_lock, NULL);
+
+       /* lwpctl state is not copied across fork. */
+       if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, &self->pt_lwpctl)) {
+               err(EXIT_FAILURE, "_lwp_ctl");
+       }
+       self->pt_lid = _lwp_self();
+}
+
 /*
  * This needs to be started by the library loading code, before main()
  * gets to run, for various things that use the state of the initial thread
@@ -256,22 +281,10 @@
        }
 
        /* Tell libc that we're here and it should role-play accordingly. */
-       pthread_atfork(NULL, NULL, pthread__fork_callback);
+       pthread_atfork(pthread__prefork, pthread__fork_parent, pthread__fork_child);
        __isthreaded = 1;
 }
 
-static void
-pthread__fork_callback(void)
-{
-       struct __pthread_st *self = pthread__self();
-
-       /* lwpctl state is not copied across fork. */
-       if (_lwp_ctl(LWPCTL_FEATURE_CURCPU, &self->pt_lwpctl)) {
-               err(EXIT_FAILURE, "_lwp_ctl");
-       }
-       self->pt_lid = _lwp_self();
-}
-
 /* General-purpose thread data structure sanitization. */
 /* ARGSUSED */
 static void



Home | Main Index | Thread Index | Old Index