1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-26 23:11:19 +01:00

sys/posix/pthread: Use atomic_int_t to handle spin lock

This commit is contained in:
Joakim Gebart 2015-04-26 09:22:17 +02:00
parent 42f38122c5
commit 718664dacc

View File

@ -13,6 +13,7 @@
* @brief Spin locks.
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
* @author René Kijewski <kijewski@inf.fu-berlin.de>
* @author Joakim Gebart <joakim.gebart@eistec.se>
* @}
*/
@ -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;
}