Module Name: src
Committed By: christos
Date: Mon Oct 31 23:53:12 UTC 2016
Modified Files:
src/lib/libpthread: pthread_mutex.c
Log Message:
Don't spin if we already own the mutex, otherwise we will get stuck spinning
forever, fixes timemutex{1,2} tests.
To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/lib/libpthread/pthread_mutex.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libpthread/pthread_mutex.c
diff -u src/lib/libpthread/pthread_mutex.c:1.62 src/lib/libpthread/pthread_mutex.c:1.63
--- src/lib/libpthread/pthread_mutex.c:1.62 Sun Jul 17 09:49:43 2016
+++ src/lib/libpthread/pthread_mutex.c Mon Oct 31 19:53:12 2016
@@ -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 @@ again:
* 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 @@ pthread__mutex_lock_slow(pthread_mutex_t
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) {