diff options
-rw-r--r-- | lib/libc/thread/rthread.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/libc/thread/rthread.c b/lib/libc/thread/rthread.c index f26e85ffd31..c61d8fd6f03 100644 --- a/lib/libc/thread/rthread.c +++ b/lib/libc/thread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.7 2017/12/05 13:45:31 kettenis Exp $ */ +/* $OpenBSD: rthread.c,v 1.8 2018/05/13 16:21:26 visa Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -19,6 +19,9 @@ * The infrastructure of rthreads */ +#include <sys/types.h> +#include <sys/atomic.h> + #include <pthread.h> #include <stdlib.h> #include <tib.h> @@ -45,18 +48,24 @@ _spinlock(volatile _atomic_lock_t *lock) { while (_atomic_lock(lock)) sched_yield(); + membar_enter_after_atomic(); } DEF_STRONG(_spinlock); int _spinlocktry(volatile _atomic_lock_t *lock) { - return 0 == _atomic_lock(lock); + if (_atomic_lock(lock) == 0) { + membar_enter_after_atomic(); + return 1; + } + return 0; } void _spinunlock(volatile _atomic_lock_t *lock) { + membar_exit(); *lock = _ATOMIC_LOCK_UNLOCKED; } DEF_STRONG(_spinunlock); |