summaryrefslogtreecommitdiff
path: root/lib/libpthread/pthread_lock.c
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2007-03-02 17:34:21 +0000
committerad <ad@NetBSD.org>2007-03-02 17:34:21 +0000
commit1bcb6087a6c8b1df6b8adea68e9ba6eac1237453 (patch)
tree892c8515996f40dbc2beb57f0f98d279b3df5f74 /lib/libpthread/pthread_lock.c
parent398cd7c7b33e76006e64cdab42d9f586d0cb9011 (diff)
On x86, issue the pause instruction while spinning.
Diffstat (limited to 'lib/libpthread/pthread_lock.c')
-rw-r--r--lib/libpthread/pthread_lock.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/libpthread/pthread_lock.c b/lib/libpthread/pthread_lock.c
index a7e700c0af1..007f86402a8 100644
--- a/lib/libpthread/pthread_lock.c
+++ b/lib/libpthread/pthread_lock.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_lock.c,v 1.16 2006/12/24 18:39:46 ad Exp $ */
+/* $NetBSD: pthread_lock.c,v 1.17 2007/03/02 17:34:21 ad Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_lock.c,v 1.16 2006/12/24 18:39:46 ad Exp $");
+__RCSID("$NetBSD: pthread_lock.c,v 1.17 2007/03/02 17:34:21 ad Exp $");
#include <sys/types.h>
#include <sys/lock.h>
@@ -55,6 +55,13 @@ __RCSID("$NetBSD: pthread_lock.c,v 1.16 2006/12/24 18:39:46 ad Exp $");
#define SDPRINTF(x)
#endif
+/* This does not belong here. */
+#if defined(i386) || defined(__x86_64__)
+#define smt_pause() __asm __volatile("rep; nop" ::: "memory")
+#else
+#define smt_pause() /* nothing */
+#endif
+
extern int pthread__nspins;
RAS_DECL(pthread__lock);
@@ -166,8 +173,9 @@ pthread_spinlock(pthread_t thread, pthread_spin_t *lock)
++thread->pt_spinlocks;
do {
- while (((ret = pthread__simple_lock_try(lock)) == 0) && --count)
- /* XXX For at least x86, issue 'pause' instruction */;
+ while (((ret = pthread__simple_lock_try(lock)) == 0) && --count) {
+ smt_pause();
+ }
if (ret == 1)
break;
@@ -323,8 +331,9 @@ pthread_spin_lock(pthread_spinlock_t *lock)
return EINVAL;
#endif
- while (pthread__simple_lock_try(&lock->pts_spin) == 0)
- /* spin */ ;
+ while (pthread__simple_lock_try(&lock->pts_spin) == 0) {
+ smt_pause();
+ }
return 0;
}