diff --git a/libs/libc/machine/arch_atomic.c b/libs/libc/machine/arch_atomic.c index 16e7495494..9d2004d347 100644 --- a/libs/libc/machine/arch_atomic.c +++ b/libs/libc/machine/arch_atomic.c @@ -32,6 +32,47 @@ * Pre-processor Definitions ****************************************************************************/ +#define STORE(n, type) \ + \ + void __atomic_store_ ## n (type *ptr, \ + type value, \ + int memorder) \ + { \ + irqstate_t irqstate = spin_lock_irqsave(NULL); \ + \ + *ptr = value; \ + \ + spin_unlock_irqrestore(NULL, irqstate); \ + } + +#define LOAD(n, type) \ + \ + type __atomic_load_ ## n (type *ptr, \ + int memorder) \ + { \ + irqstate_t irqstate = spin_lock_irqsave(NULL); \ + \ + type ret = *ptr; \ + \ + spin_unlock_irqrestore(NULL, irqstate); \ + return ret; \ + } + +#define EXCHANGE(n, type) \ + \ + type __atomic_exchange_ ## n (type *ptr, \ + type value, \ + int memorder) \ + { \ + irqstate_t irqstate = spin_lock_irqsave(NULL); \ + \ + type ret = *ptr; \ + *ptr = value; \ + \ + spin_unlock_irqrestore(NULL, irqstate); \ + return ret; \ + } + #define CMP_EXCHANGE(n, type) \ \ bool __atomic_compare_exchange_ ## n (type *mem, \ @@ -138,6 +179,78 @@ * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: __atomic_store_1 + ****************************************************************************/ + +STORE(1, uint8_t) + +/**************************************************************************** + * Name: __atomic_store_2 + ****************************************************************************/ + +STORE(2, uint16_t) + +/**************************************************************************** + * Name: __atomic_store_4 + ****************************************************************************/ + +STORE(4, uint32_t) + +/**************************************************************************** + * Name: __atomic_store_8 + ****************************************************************************/ + +STORE(8, uint64_t) + +/**************************************************************************** + * Name: __atomic_load_1 + ****************************************************************************/ + +LOAD(1, uint8_t) + +/**************************************************************************** + * Name: __atomic_load__2 + ****************************************************************************/ + +LOAD(2, uint16_t) + +/**************************************************************************** + * Name: __atomic_load__4 + ****************************************************************************/ + +LOAD(4, uint32_t) + +/**************************************************************************** + * Name: __atomic_load__8 + ****************************************************************************/ + +LOAD(8, uint64_t) + +/**************************************************************************** + * Name: __atomic_exchange_1 + ****************************************************************************/ + +EXCHANGE(1, uint8_t) + +/**************************************************************************** + * Name: __atomic_exchange__2 + ****************************************************************************/ + +EXCHANGE(2, uint16_t) + +/**************************************************************************** + * Name: __atomic_exchange__4 + ****************************************************************************/ + +EXCHANGE(4, uint32_t) + +/**************************************************************************** + * Name: __atomic_exchange__8 + ****************************************************************************/ + +EXCHANGE(8, uint64_t) + /**************************************************************************** * Name: __atomic_compare_exchange_1 ****************************************************************************/