Source-Changes-HG archive

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

[src/netbsd-3-0]: src/lib/libpthread Pull up following revision(s) (requested...



details:   https://anonhg.NetBSD.org/src/rev/544d7d0c0498
branches:  netbsd-3-0
changeset: 579281:544d7d0c0498
user:      ghen <ghen%NetBSD.org@localhost>
date:      Fri Aug 25 11:37:00 2006 +0000

description:
Pull up following revision(s) (requested by wrstuden in ticket #1474):
        lib/libpthread/pthread_mutex.c: revision 1.22
Close a window in which we can not notice a recently-slept-on-our
mutex thread, thus leaving a thread sleeping on an unlocked mutex.
Reviewed by myself and Christos.
Problem reported by Arne H. Juul, arnej at pvv dot ntnu dot no,
in PR 26208. This fix represents option 1 presented in the PR.

diffstat:

 lib/libpthread/pthread_mutex.c |  12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diffs (54 lines):

diff -r 64930c580899 -r 544d7d0c0498 lib/libpthread/pthread_mutex.c
--- a/lib/libpthread/pthread_mutex.c    Fri Aug 25 11:34:02 2006 +0000
+++ b/lib/libpthread/pthread_mutex.c    Fri Aug 25 11:37:00 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_mutex.c,v 1.18.6.1 2005/11/01 20:01:33 jmc Exp $       */
+/*     $NetBSD: pthread_mutex.c,v 1.18.6.1.2.1 2006/08/25 11:37:00 ghen Exp $  */
 
 /*-
  * Copyright (c) 2001, 2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_mutex.c,v 1.18.6.1 2005/11/01 20:01:33 jmc Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.18.6.1.2.1 2006/08/25 11:37:00 ghen Exp $");
 
 #include <errno.h>
 #include <limits.h>
@@ -337,12 +337,13 @@
 
        GET_MUTEX_PRIVATE(mutex, mp);
 
+       self = pthread_self();
        /*
         * These tests can be performed without holding the
         * interlock because these fields are only modified
         * if we know we own the mutex.
         */
-       weown = (pthread__id(mutex->ptm_owner) == pthread__self());
+       weown = (pthread__id(mutex->ptm_owner) == self);
        switch (mp->type) {
        case PTHREAD_MUTEX_RECURSIVE:
                if (!weown)
@@ -378,9 +379,8 @@
         * examination of the queue; if so, no harm is done, as the
         * waiter will loop and see that the mutex is still locked.
         */
+       pthread_spinlock(self, &mutex->ptm_interlock);
        if (!PTQ_EMPTY(&mutex->ptm_blocked)) {
-               self = pthread__self();
-               pthread_spinlock(self, &mutex->ptm_interlock);
                blocked = PTQ_FIRST(&mutex->ptm_blocked);
                if (blocked) {
                        PTQ_REMOVE(&mutex->ptm_blocked, blocked, pt_sleep);
@@ -388,8 +388,8 @@
                        /* Give the head of the blocked queue another try. */
                        pthread__sched(self, blocked);
                }
-               pthread_spinunlock(self, &mutex->ptm_interlock);
        }
+       pthread_spinunlock(self, &mutex->ptm_interlock);
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index