diff --git a/include/sys/atomic.h b/include/sys/atomic.h index 69b8193cdae..7de01e44058 100644 --- a/include/sys/atomic.h +++ b/include/sys/atomic.h @@ -49,11 +49,11 @@ static inline bool atomic_cas(atomic_t *target, atomic_val_t old_value, __ATOMIC_SEQ_CST); } #elif defined(CONFIG_ATOMIC_OPERATIONS_C) -__syscall int atomic_cas(atomic_t *target, atomic_val_t old_value, +__syscall bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value); #else -extern int atomic_cas(atomic_t *target, atomic_val_t old_value, +extern bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value); #endif diff --git a/kernel/atomic_c.c b/kernel/atomic_c.c index 15d42d0f410..56797e9f546 100644 --- a/kernel/atomic_c.c +++ b/kernel/atomic_c.c @@ -63,10 +63,10 @@ static struct k_spinlock lock; * * This routine provides the compare-and-set operator. If the original value at * equals , then is stored at and the - * function returns 1. + * function returns true. * * If the original value at does not equal , then the store - * is not done and the function returns 0. + * is not done and the function returns false. * * The reading of the original value at , the comparison, * and the write of the new value (if it occurs) all happen atomically with @@ -75,19 +75,19 @@ static struct k_spinlock lock; * @param target address to be tested * @param old_value value to compare against * @param new_value value to compare against - * @return Returns 1 if is written, 0 otherwise. + * @return Returns true if is written, false otherwise. */ -int z_impl_atomic_cas(atomic_t *target, atomic_val_t old_value, - atomic_val_t new_value) +bool z_impl_atomic_cas(atomic_t *target, atomic_val_t old_value, + atomic_val_t new_value) { k_spinlock_key_t key; - int ret = 0; + int ret = false; key = k_spin_lock(&lock); if (*target == old_value) { *target = new_value; - ret = 1; + ret = true; } k_spin_unlock(&lock, key); @@ -96,8 +96,8 @@ int z_impl_atomic_cas(atomic_t *target, atomic_val_t old_value, } #ifdef CONFIG_USERSPACE -int z_vrfy_atomic_cas(atomic_t *target, atomic_val_t old_value, - atomic_val_t new_value) +bool z_vrfy_atomic_cas(atomic_t *target, atomic_val_t old_value, + atomic_val_t new_value) { Z_OOPS(Z_SYSCALL_MEMORY_WRITE(target, sizeof(atomic_t))); diff --git a/tests/kernel/common/src/atomic.c b/tests/kernel/common/src/atomic.c index a4e475b06fd..abba01f682e 100644 --- a/tests/kernel/common/src/atomic.c +++ b/tests/kernel/common/src/atomic.c @@ -34,9 +34,9 @@ void test_atomic(void) oldvalue = 6; /* atomic_cas() */ - zassert_true((atomic_cas(&target, oldvalue, value) == 0), "atomic_cas"); + zassert_false(atomic_cas(&target, oldvalue, value), "atomic_cas"); target = 6; - zassert_true((atomic_cas(&target, oldvalue, value) == 1), "atomic_cas"); + zassert_true(atomic_cas(&target, oldvalue, value), "atomic_cas"); zassert_true((target == value), "atomic_cas"); /* atomic_add() */