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 spin if we already own the mutex, other...



details:   https://anonhg.NetBSD.org/src/rev/be7fdbe8f34a
branches:  trunk
changeset: 348649:be7fdbe8f34a
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Oct 31 23:53:12 2016 +0000

description:
Don't spin if we already own the mutex, otherwise we will get stuck spinning
forever, fixes timemutex{1,2} tests.

diffstat:

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

diffs (38 lines):

diff -r 3e601f773dc7 -r be7fdbe8f34a lib/libpthread/pthread_mutex.c
--- a/lib/libpthread/pthread_mutex.c    Mon Oct 31 23:51:20 2016 +0000
+++ b/lib/libpthread/pthread_mutex.c    Mon Oct 31 23:53:12 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_mutex.c,v 1.62 2016/07/17 13:49:43 skrll Exp $ */
+/*     $NetBSD: pthread_mutex.c,v 1.63 2016/10/31 23:53:12 christos 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.62 2016/07/17 13:49:43 skrll Exp $");
+__RCSID("$NetBSD: pthread_mutex.c,v 1.63 2016/10/31 23:53:12 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/lwpctl.h>
@@ -298,7 +298,8 @@
         * we see that the holder is running again.
         */
        membar_sync();
-       pthread__mutex_spin(ptm, owner);
+       if (MUTEX_OWNER(owner) != (uintptr_t)self)
+               pthread__mutex_spin(ptm, owner);
 
        if (membar_consumer(), !MUTEX_HAS_WAITERS(ptm->ptm_owner)) {
                goto again;
@@ -338,7 +339,8 @@
        serrno = errno;
        for (;; owner = ptm->ptm_owner) {
                /* Spin while the owner is running. */
-               owner = pthread__mutex_spin(ptm, owner);
+               if (MUTEX_OWNER(owner) != (uintptr_t)self)
+                       owner = pthread__mutex_spin(ptm, owner);
 
                /* If it has become free, try to acquire it again. */
                if (MUTEX_OWNER(owner) == 0) {



Home | Main Index | Thread Index | Old Index