From 718664daccdaa42301a093914e46cf08df01ca34 Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Sun, 26 Apr 2015 09:22:17 +0200 Subject: [PATCH] sys/posix/pthread: Use atomic_int_t to handle spin lock --- sys/posix/pthread/pthread_spin.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sys/posix/pthread/pthread_spin.c b/sys/posix/pthread/pthread_spin.c index 14319f1bf1..07806cc943 100644 --- a/sys/posix/pthread/pthread_spin.c +++ b/sys/posix/pthread/pthread_spin.c @@ -13,6 +13,7 @@ * @brief Spin locks. * @author Christian Mehlis * @author René Kijewski + * @author Joakim Gebart * @} */ @@ -46,9 +47,10 @@ int pthread_spin_lock(pthread_spinlock_t *lock) return EINVAL; } - while (atomic_set_return((unsigned *) lock, 1) != 0) { + while (atomic_set_to_one((int *)lock) == 0) { /* spin */ } + return 0; } @@ -58,7 +60,11 @@ int pthread_spin_trylock(pthread_spinlock_t *lock) return EINVAL; } - return atomic_set_return((unsigned *) lock, 1) == 0 ? 0 : EBUSY; + if (atomic_set_to_one((int *)lock) == 0) { + return EBUSY; + } + + return 0; } int pthread_spin_unlock(pthread_spinlock_t *lock) @@ -67,5 +73,9 @@ int pthread_spin_unlock(pthread_spinlock_t *lock) return EINVAL; } - return atomic_set_return((unsigned *) lock, 0) != 0 ? 0 : EPERM; + if (atomic_set_to_zero((int *)lock) == 0) { + return EPERM; + } + + return 0; }