diff options
Diffstat (limited to 'lib/librthread')
-rw-r--r-- | lib/librthread/rthread_mutex.c | 13 | ||||
-rw-r--r-- | lib/librthread/synch.h | 5 |
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) { |