From: mpi Date: Mon, 29 May 2017 14:47:54 +0000 (+0000) Subject: SPINLOCK_SPIN_HOOK is no more, define our own set of macros. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ad36c4aee20b7adfcb453d0a0ca6a5c80dd47115;p=openbsd SPINLOCK_SPIN_HOOK is no more, define our own set of macros. Prodded by kettenis@ and tedu@ --- 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 * Copyright (c) 2012 Philip Guenther @@ -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 /* for SPINLOCK_SPIN_HOOK */ -#define SPINLOCK_SPIN_COUNT 128 - static inline int _wake(volatile uint32_t *p, int n) {