Source-Changes-HG archive

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

[src/trunk]: src/lib/libpthread Drop most of the logic associated with pthrea...



details:   https://anonhg.NetBSD.org/src/rev/ef2f44a3bee9
branches:  trunk
changeset: 1009173:ef2f44a3bee9
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Apr 14 23:35:07 2020 +0000

description:
Drop most of the logic associated with pthread__started.

The pthread_cond logic is a questionable optimisation at best and the
post-fork logic is plainly broken.

diffstat:

 lib/libpthread/pthread.c      |  47 +++--------------------------------------
 lib/libpthread/pthread_cond.c |  48 +-----------------------------------------
 2 files changed, 6 insertions(+), 89 deletions(-)

diffs (169 lines):

diff -r 15d444f16535 -r ef2f44a3bee9 lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c  Tue Apr 14 22:42:18 2020 +0000
+++ b/lib/libpthread/pthread.c  Tue Apr 14 23:35:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $      */
+/*     $NetBSD: pthread.c,v 1.168 2020/04/14 23:35:07 joerg Exp $      */
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.167 2020/02/16 17:45:11 kamil Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.168 2020/04/14 23:35:07 joerg Exp $");
 
 #define        __EXPOSE_STACK  1
 
@@ -84,8 +84,6 @@
 static void    pthread__initmain(pthread_t *);
 static void    pthread__fork_callback(void);
 static void    pthread__reap(pthread_t);
-static void    pthread__child_callback(void);
-static void    pthread__start(void);
 
 void   pthread__init(void);
 
@@ -274,36 +272,6 @@
        self->pt_lid = _lwp_self();
 }
 
-static void
-pthread__child_callback(void)
-{
-
-       /*
-        * Clean up data structures that a forked child process might
-        * trip over. Note that if threads have been created (causing
-        * this handler to be registered) the standards say that the
-        * child will trigger undefined behavior if it makes any
-        * pthread_* calls (or any other calls that aren't
-        * async-signal-safe), so we don't really have to clean up
-        * much. Anything that permits some pthread_* calls to work is
-        * merely being polite.
-        */
-       pthread__started = 0;
-}
-
-static void
-pthread__start(void)
-{
-
-       /*
-        * Per-process timers are cleared by fork(); despite the
-        * various restrictions on fork() and threads, it's legal to
-        * fork() before creating any threads.
-        */
-       pthread_atfork(NULL, NULL, pthread__child_callback);
-}
-
-
 /* General-purpose thread data structure sanitization. */
 /* ARGSUSED */
 static void
@@ -424,15 +392,6 @@
                return __libc_thr_create_stub(thread, attr, startfunc, arg);
        }
 
-       /*
-        * It's okay to check this without a lock because there can
-        * only be one thread before it becomes true.
-        */
-       if (pthread__started == 0) {
-               pthread__start();
-               pthread__started = 1;
-       }
-
        if (attr == NULL)
                nattr = pthread_default_attr;
        else if (attr->pta_magic == PT_ATTR_MAGIC)
@@ -440,6 +399,8 @@
        else
                return EINVAL;
 
+       pthread__started = 1;
+
        /* Fetch misc. attributes from the attr structure. */
        name = NULL;
        if ((p = nattr.pta_private) != NULL)
diff -r 15d444f16535 -r ef2f44a3bee9 lib/libpthread/pthread_cond.c
--- a/lib/libpthread/pthread_cond.c     Tue Apr 14 22:42:18 2020 +0000
+++ b/lib/libpthread/pthread_cond.c     Tue Apr 14 23:35:07 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $  */
+/*     $NetBSD: pthread_cond.c,v 1.68 2020/04/14 23:35:07 joerg Exp $  */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_cond.c,v 1.67 2020/01/29 15:07:46 kamil Exp $");
+__RCSID("$NetBSD: pthread_cond.c,v 1.68 2020/04/14 23:35:07 joerg Exp $");
 
 #include <stdlib.h>
 #include <errno.h>
@@ -59,11 +59,6 @@
 
 int    _sys___nanosleep50(const struct timespec *, struct timespec *);
 
-extern int pthread__started;
-
-static int pthread_cond_wait_nothread(pthread_t, pthread_mutex_t *,
-    pthread_cond_t *, const struct timespec *);
-
 int    _pthread_cond_has_waiters_np(pthread_cond_t *);
 
 __weak_alias(pthread_cond_has_waiters_np,_pthread_cond_has_waiters_np)
@@ -149,10 +144,6 @@
 
        self = pthread__self();
 
-       /* Just hang out for a while if threads aren't running yet. */
-       if (__predict_false(pthread__started == 0)) {
-               return pthread_cond_wait_nothread(self, mutex, cond, abstime);
-       }
        if (__predict_false(self->pt_cancel)) {
                pthread__cancelled();
        }
@@ -431,38 +422,3 @@
        return EINVAL;
 }
 #endif
-
-/* Utility routine to hang out for a while if threads haven't started yet. */
-static int
-pthread_cond_wait_nothread(pthread_t self, pthread_mutex_t *mutex,
-    pthread_cond_t *cond, const struct timespec *abstime)
-{
-       struct timespec now, diff;
-       int retval;
-
-       if (abstime == NULL) {
-               diff.tv_sec = 99999999;
-               diff.tv_nsec = 0;
-       } else {
-               clockid_t clck = pthread_cond_getclock(cond);
-               clock_gettime(clck, &now);
-               if  (timespeccmp(abstime, &now, <))
-                       timespecclear(&diff);
-               else
-                       timespecsub(abstime, &now, &diff);
-       }
-
-       do {
-               pthread__testcancel(self);
-               pthread_mutex_unlock(mutex);
-               retval = _sys___nanosleep50(&diff, NULL);
-               pthread_mutex_lock(mutex);
-       } while (abstime == NULL && retval == 0);
-       pthread__testcancel(self);
-
-       if (retval == 0)
-               return ETIMEDOUT;
-       else
-               /* spurious wakeup */
-               return 0;
-}



Home | Main Index | Thread Index | Old Index