Don't spin if we already own the mutex, otherwise we will get stuck spinning

forever, fixes timemutex{1,2} tests.
This commit is contained in:
christos 2016-10-31 23:53:12 +00:00
parent b6bcbcb52f
commit 6e03f6000c
1 changed files with 6 additions and 4 deletions

View File

@ -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,6 +298,7 @@ again:
* we see that the holder is running again.
*/
membar_sync();
if (MUTEX_OWNER(owner) != (uintptr_t)self)
pthread__mutex_spin(ptm, owner);
if (membar_consumer(), !MUTEX_HAS_WAITERS(ptm->ptm_owner)) {
@ -338,6 +339,7 @@ pthread__mutex_lock_slow(pthread_mutex_t *ptm, const struct timespec *ts)
serrno = errno;
for (;; owner = ptm->ptm_owner) {
/* Spin while the owner is running. */
if (MUTEX_OWNER(owner) != (uintptr_t)self)
owner = pthread__mutex_spin(ptm, owner);
/* If it has become free, try to acquire it again. */