libc:machine: add atomic_load/store/exchange API
Add atomic_load/store/exchange API Change-Id: I6196b077d1e76cd1e0506ee66e2885e541525eb1
This commit is contained in:
parent
60b6199120
commit
e01e5f5008
@ -32,6 +32,47 @@
|
|||||||
* Pre-processor Definitions
|
* 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) \
|
#define CMP_EXCHANGE(n, type) \
|
||||||
\
|
\
|
||||||
bool __atomic_compare_exchange_ ## n (type *mem, \
|
bool __atomic_compare_exchange_ ## n (type *mem, \
|
||||||
@ -138,6 +179,78 @@
|
|||||||
* Public Functions
|
* 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
|
* Name: __atomic_compare_exchange_1
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user