summaryrefslogtreecommitdiff
path: root/lib/librthread
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-05-29 14:47:55 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-05-29 14:47:55 +0000
commita10217b48c43ffbe36964f9aae7f09e1e250efe9 (patch)
tree8998a7c8b787901e4231dcff96a6a2d89c1deba7 /lib/librthread
parenta234aa6c27964d9296102670ab83142e879899af (diff)
SPINLOCK_SPIN_HOOK is no more, define our own set of macros.
Prodded by kettenis@ and tedu@
Diffstat (limited to 'lib/librthread')
-rw-r--r--lib/librthread/rthread_mutex.c13
-rw-r--r--lib/librthread/synch.h5
2 files changed, 11 insertions, 7 deletions
diff --git a/lib/librthread/rthread_mutex.c b/lib/librthread/rthread_mutex.c
index 9ee8f1b75af..ea2db8131b3 100644
--- a/lib/librthread/rthread_mutex.c
+++ b/lib/librthread/rthread_mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_mutex.c,v 1.2 2017/05/28 09:45:25 mpi Exp $ */
+/* $OpenBSD: rthread_mutex.c,v 1.3 2017/05/29 14:47:54 mpi Exp $ */
/*
* Copyright (c) 2017 Martin Pieuchot <mpi@openbsd.org>
* Copyright (c) 2012 Philip Guenther <guenther@openbsd.org>
@@ -38,6 +38,13 @@ enum {
CONTENDED = 2, /* threads waiting for this mutex */
};
+#define SPIN_COUNT 128
+#if defined(__i386__) || defined(__amd64__)
+#define SPIN_WAIT() asm volatile("pause": : : "memory")
+#else
+#define SPIN_WAIT() do { } while (0)
+#endif
+
static _atomic_lock_t static_init_lock = _SPINLOCK_UNLOCKED;
int
@@ -164,11 +171,11 @@ _rthread_mutex_timedlock(pthread_mutex_t *mutexp, int trywait,
return (error);
/* Try hard to not enter the kernel. */
- for (i = 0; i < SPINLOCK_SPIN_COUNT; i ++) {
+ for (i = 0; i < SPIN_COUNT; i ++) {
if (mutex->lock == UNLOCKED)
break;
- SPINLOCK_SPIN_HOOK;
+ SPIN_WAIT();
}
lock = atomic_cas_uint(&mutex->lock, UNLOCKED, LOCKED);
diff --git a/lib/librthread/synch.h b/lib/librthread/synch.h
index 8f3f241c2f7..0c69a39164e 100644
--- a/lib/librthread/synch.h
+++ b/lib/librthread/synch.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: synch.h,v 1.1 2017/05/27 14:20:39 mpi Exp $ */
+/* $OpenBSD: synch.h,v 1.2 2017/05/29 14:47:54 mpi Exp $ */
/*
* Copyright (c) 2017 Martin Pieuchot
*
@@ -21,9 +21,6 @@
REDIRECT_SYSCALL(futex);
-#include <machine/lock.h> /* for SPINLOCK_SPIN_HOOK */
-#define SPINLOCK_SPIN_COUNT 128
-
static inline int
_wake(volatile uint32_t *p, int n)
{