From 597db0358d5ee0562bf02d8351c88caffb57577a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Nohlg=C3=A5rd?= Date: Sat, 23 Jul 2016 17:21:20 +0200 Subject: [PATCH] sys/posix/pthread: Use C11 atomic instead of atomic.h --- sys/posix/pthread/include/pthread_spin.h | 4 ++-- sys/posix/pthread/pthread_spin.c | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sys/posix/pthread/include/pthread_spin.h b/sys/posix/pthread/include/pthread_spin.h index 1389ec76e1..2661029a7e 100644 --- a/sys/posix/pthread/include/pthread_spin.h +++ b/sys/posix/pthread/include/pthread_spin.h @@ -20,7 +20,7 @@ #ifndef SYS_POSIX_PTHREAD_SPIN_H #define SYS_POSIX_PTHREAD_SPIN_H -#include +#include #ifdef __cplusplus extern "C" { @@ -33,7 +33,7 @@ extern "C" { * Use irq_disable() and irq_restore() for shortterm locks instead. */ typedef struct { - atomic_int_t value; + atomic_flag flag; } pthread_spinlock_t; /** diff --git a/sys/posix/pthread/pthread_spin.c b/sys/posix/pthread/pthread_spin.c index 39b330dc7a..bd1de9d968 100644 --- a/sys/posix/pthread/pthread_spin.c +++ b/sys/posix/pthread/pthread_spin.c @@ -17,8 +17,10 @@ * @} */ +#include +#include +#include #include "pthread.h" -#include "atomic.h" int pthread_spin_init(pthread_spinlock_t *lock, int pshared) { @@ -27,7 +29,7 @@ int pthread_spin_init(pthread_spinlock_t *lock, int pshared) } (void) pshared; - ATOMIC_VALUE(lock->value) = 0; + atomic_flag_clear(&(lock->flag)); return 0; } @@ -47,7 +49,7 @@ int pthread_spin_lock(pthread_spinlock_t *lock) return EINVAL; } - while (atomic_set_to_one(&(lock->value)) == 0) { + while (atomic_flag_test_and_set(&(lock->flag))) { /* spin */ } @@ -60,7 +62,7 @@ int pthread_spin_trylock(pthread_spinlock_t *lock) return EINVAL; } - if (atomic_set_to_one(&(lock->value)) == 0) { + if (atomic_flag_test_and_set(&(lock->flag))) { return EBUSY; } @@ -73,9 +75,7 @@ int pthread_spin_unlock(pthread_spinlock_t *lock) return EINVAL; } - if (atomic_set_to_zero(&(lock->value)) == 0) { - return EPERM; - } + atomic_flag_clear(&(lock->flag)); return 0; }