Source-Changes-HG archive

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

[src/trunk]: src/lib/libpthread Don't just look only at the first element in ...



details:   https://anonhg.NetBSD.org/src/rev/93c0423f2afd
branches:  trunk
changeset: 747870:93c0423f2afd
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Oct 03 23:49:50 2009 +0000

description:
Don't just look only at the first element in the deadqueue to find lwp's
to reuse, because if we lose the race with the kernel we are never going
to reuse any elements. Look in the whole list instead.
XXX: should be pulled up to 5.x

diffstat:

 lib/libpthread/pthread.c |  30 ++++++++++++------------------
 1 files changed, 12 insertions(+), 18 deletions(-)

diffs (52 lines):

diff -r 1ad123d805c9 -r 93c0423f2afd lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c  Sat Oct 03 22:55:48 2009 +0000
+++ b/lib/libpthread/pthread.c  Sat Oct 03 23:49:50 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread.c,v 1.112 2009/07/02 09:59:00 joerg Exp $      */
+/*     $NetBSD: pthread.c,v 1.113 2009/10/03 23:49:50 christos Exp $   */
 
 /*-
  * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.112 2009/07/02 09:59:00 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.113 2009/10/03 23:49:50 christos Exp $");
 
 #define        __EXPOSE_STACK  1
 
@@ -353,23 +353,17 @@
         */
        if (!PTQ_EMPTY(&pthread__deadqueue)) {
                pthread_mutex_lock(&pthread__deadqueue_lock);
-               newthread = PTQ_FIRST(&pthread__deadqueue);
-               if (newthread != NULL) {
-                       PTQ_REMOVE(&pthread__deadqueue, newthread, pt_deadq);
-                       pthread_mutex_unlock(&pthread__deadqueue_lock);
+               PTQ_FOREACH(newthread, &pthread__deadqueue, pt_deadq) {
                        /* Still running? */
-                       if (newthread->pt_lwpctl->lc_curcpu !=
-                           LWPCTL_CPU_EXITED &&
-                           (_lwp_kill(newthread->pt_lid, 0) == 0 ||
-                           errno != ESRCH)) {
-                               pthread_mutex_lock(&pthread__deadqueue_lock);
-                               PTQ_INSERT_TAIL(&pthread__deadqueue,
-                                   newthread, pt_deadq);
-                               pthread_mutex_unlock(&pthread__deadqueue_lock);
-                               newthread = NULL;
-                       }
-               } else
-                       pthread_mutex_unlock(&pthread__deadqueue_lock);
+                       if (newthread->pt_lwpctl->lc_curcpu ==
+                           LWPCTL_CPU_EXITED ||
+                           (_lwp_kill(newthread->pt_lid, 0) == -1 &&
+                           errno == ESRCH))
+                               break;
+               }
+               if (newthread)
+                       PTQ_REMOVE(&pthread__deadqueue, newthread, pt_deadq);
+               pthread_mutex_unlock(&pthread__deadqueue_lock);
        }
 
        /*



Home | Main Index | Thread Index | Old Index