-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arch_atomic : Introduce CONFIG_LIBC_ARCH_NXATOMIC #14681
Open
TakuyaMiyasita
wants to merge
1
commit into
apache:master
Choose a base branch
from
TakuyaMiyasita:fix/1730-platform-atomic
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+490
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,109 @@ | |
#define ATOMIC_FLAG_INIT 0 | ||
#define ATOMIC_VAR_INIT(value) (value) | ||
|
||
#ifdef CONFIG_LIBC_ARCH_NXATOMIC | ||
|
||
#define atomic_store_n(obj, val, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_store_1(obj, val, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_store_2(obj, val, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_store_4(obj, val, type) : \ | ||
__nx_atomic_store_8(obj, val, type)) | ||
|
||
#define atomic_store(obj, val) atomic_store_n(obj, val, __ATOMIC_RELAXED) | ||
#define atomic_store_explicit(obj, val, type) atomic_store_n(obj, val, type) | ||
#define atomic_init(obj, val) atomic_store(obj, val) | ||
|
||
#define atomic_load_n(obj, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_load_1(obj, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_load_2(obj, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_load_4(obj, type) : \ | ||
__nx_atomic_load_8(obj, type)) | ||
|
||
#define atomic_load(obj) atomic_load_n(obj, __ATOMIC_RELAXED) | ||
#define atomic_load_explicit(obj, type) atomic_load_n(obj, type) | ||
|
||
#define atomic_exchange_n(obj, val, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_exchange_1(obj, val, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_exchange_2(obj, val, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_exchange_4(obj, val, type) : \ | ||
__nx_atomic_exchange_8(obj, val, type)) | ||
|
||
#define atomic_exchange(obj, val) atomic_exchange_n(obj, val, __ATOMIC_RELAXED) | ||
#define atomic_exchange_explicit(obj, val, type) atomic_exchange_n(obj, val, type) | ||
|
||
#define atomic_compare_exchange_n(obj, expected, desired, weak, success, failure) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_compare_exchange_1(obj, expected, desired, weak, success, failure) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_compare_exchange_2(obj, expected, desired, weak, success, failure) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_compare_exchange_4(obj, expected, desired, weak, success, failure) : \ | ||
__nx_atomic_compare_exchange_8(obj, expected, desired, weak, success, failure)) | ||
|
||
#define atomic_compare_exchange_strong(obj, expected, desired) \ | ||
atomic_compare_exchange_n(obj, expected, desired, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED) | ||
#define atomic_compare_exchange_strong_explicit(obj, expected, desired, success, failure) \ | ||
atomic_compare_exchange_n(obj, expected, desired, false, success, failure) | ||
#define atomic_compare_exchange_weak(obj, expected, desired) \ | ||
atomic_compare_exchange_n(obj, expected, desired, true, __ATOMIC_RELAXED, __ATOMIC_RELAXED) | ||
#define atomic_compare_exchange_weak_explicit(obj, expected, desired, success, failure) \ | ||
atomic_compare_exchange_n(obj, expected, desired, true, success, failure) | ||
|
||
#define atomic_flag_test_and_set_n(obj, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_flag_test_and_set_1(obj, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_flag_test_and_set_2(obj, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_flag_test_and_set_4(obj, type) : \ | ||
__nx_atomic_flag_test_and_set_8(obj, type)) | ||
|
||
#define atomic_flag_test_and_set(obj) atomic_flag_test_and_set_n(obj, __ATOMIC_RELAXED) | ||
#define atomic_flag_test_and_set_explicit(obj, type) atomic_flag_test_and_set_n(obj, 1, type) | ||
#define atomic_flag_clear(obj) atomic_store(obj, 0) | ||
#define atomic_flag_clear_explicit(obj, type) atomic_store_explicit(obj, 0, type) | ||
|
||
#define atomic_fetch_and_n(obj, val, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_fetch_and_1(obj, val, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_fetch_and_2(obj, val, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_fetch_and_4(obj, val, type) : \ | ||
__nx_atomic_fetch_and_8(obj, val, type)) | ||
|
||
#define atomic_fetch_and(obj, val) atomic_fetch_and_n(obj, val, __ATOMIC_RELAXED) | ||
#define atomic_fetch_and_explicit(obj, val, type) atomic_fetch_and_n(obj, val, type) | ||
|
||
#define atomic_fetch_or_n(obj, val, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_fetch_or_1(obj, val, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_fetch_or_2(obj, val, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_fetch_or_4(obj, val, type) : \ | ||
__nx_atomic_fetch_or_8(obj, val, type)) | ||
|
||
#define atomic_fetch_or(obj, val) atomic_fetch_or_n(obj, val, __ATOMIC_RELAXED) | ||
#define atomic_fetch_or_explicit(obj, val, type) atomic_fetch_or_n(obj, val, type) | ||
|
||
#define atomic_fetch_xor_n(obj, val, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_fetch_xor_1(obj, val, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_fetch_xor_2(obj, val, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_fetch_xor_4(obj, val, type) : \ | ||
__nx_atomic_fetch_xor_8(obj, val, type)) | ||
|
||
#define atomic_fetch_xor(obj, val) atomic_fetch_xor_n(obj, val, __ATOMIC_RELAXED) | ||
#define atomic_fetch_xor_explicit(obj, val, type) atomic_fetch_xor_n(obj, val, type) | ||
|
||
#define atomic_fetch_add_n(obj, val, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_fetch_add_1(obj, val, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_fetch_add_2(obj, val, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_fetch_add_4(obj, val, type) : \ | ||
__nx_atomic_fetch_add_8(obj, val, type)) | ||
|
||
#define atomic_fetch_add(obj, val) atomic_fetch_add_n(obj, val, __ATOMIC_RELAXED) | ||
#define atomic_fetch_add_explicit(obj, val, type) atomic_fetch_add_n(obj, val, type) | ||
|
||
#define atomic_fetch_sub_n(obj, val, type) \ | ||
(sizeof(*(obj)) == 1 ? __nx_atomic_fetch_sub_1(obj, val, type) : \ | ||
sizeof(*(obj)) == 2 ? __nx_atomic_fetch_sub_2(obj, val, type) : \ | ||
sizeof(*(obj)) == 4 ? __nx_atomic_fetch_sub_4(obj, val, type) : \ | ||
__nx_atomic_fetch_sub_8(obj, val, type)) | ||
|
||
#define atomic_fetch_sub(obj, val) atomic_fetch_sub_n(obj, val, __ATOMIC_RELAXED) | ||
#define atomic_fetch_sub_explicit(obj, val, type) atomic_fetch_sub_n(obj, val, type) | ||
|
||
#else | ||
|
||
#define atomic_store_n(obj, val, type) \ | ||
(sizeof(*(obj)) == 1 ? __atomic_store_1(obj, val, type) : \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's always map to to nx_ version regardless CONFIG_LIBC_ARCH_NXATOMIC |
||
sizeof(*(obj)) == 2 ? __atomic_store_2(obj, val, type) : \ | ||
|
@@ -161,6 +264,8 @@ | |
#define atomic_fetch_sub(obj, val) atomic_fetch_sub_n(obj, val, __ATOMIC_RELAXED) | ||
#define atomic_fetch_sub_explicit(obj, val, type) atomic_fetch_sub_n(obj, val, type) | ||
|
||
#endif | ||
|
||
/**************************************************************************** | ||
* Public Types | ||
****************************************************************************/ | ||
|
@@ -194,6 +299,91 @@ typedef volatile wchar_t atomic_wchar_t; | |
* Public Function Prototypes | ||
****************************************************************************/ | ||
|
||
#ifdef CONFIG_LIBC_ARCH_NXATOMIC | ||
|
||
void __nx_atomic_store_1(FAR volatile void *ptr, uint8_t value, | ||
int memorder); | ||
void __nx_atomic_store_2(FAR volatile void *ptr, uint16_t value, | ||
int memorder); | ||
void __nx_atomic_store_4(FAR volatile void *ptr, uint32_t value, | ||
int memorder); | ||
void __nx_atomic_store_8(FAR volatile void *ptr, uint64_t value, | ||
int memorder); | ||
uint8_t __nx_atomic_load_1(FAR const volatile void *ptr, int memorder); | ||
uint16_t __nx_atomic_load_2(FAR const volatile void *ptr, int memorder); | ||
uint32_t __nx_atomic_load_4(FAR const volatile void *ptr, int memorder); | ||
uint64_t __nx_atomic_load_8(FAR const volatile void *ptr, int memorder); | ||
uint8_t __nx_atomic_exchange_1(FAR volatile void *ptr, uint8_t value, | ||
int memorder); | ||
uint16_t __nx_atomic_exchange_2(FAR volatile void *ptr, uint16_t value, | ||
int memorder); | ||
uint32_t __nx_atomic_exchange_4(FAR volatile void *ptr, uint32_t value, | ||
int memorder); | ||
uint64_t __nx_atomic_exchange_8(FAR volatile void *ptr, uint64_t value, | ||
int memorder); | ||
bool __nx_atomic_compare_exchange_1(FAR volatile void *mem, FAR void *expect, | ||
uint8_t desired, bool weak, int success, | ||
int failure); | ||
bool __nx_atomic_compare_exchange_2(FAR volatile void *mem, FAR void *expect, | ||
uint16_t desired, bool weak, int success, | ||
int failure); | ||
bool __nx_atomic_compare_exchange_4(FAR volatile void *mem, FAR void *expect, | ||
uint32_t desired, bool weak, int success, | ||
int failure); | ||
bool __nx_atomic_compare_exchange_8(FAR volatile void *mem, FAR void *expect, | ||
uint64_t desired, bool weak, int success, | ||
int failure); | ||
uint8_t __nx_atomic_flag_test_and_set_1(FAR const volatile void *ptr, | ||
int memorder); | ||
uint16_t __nx_atomic_flag_test_and_set_2(FAR const volatile void *ptr, | ||
int memorder); | ||
uint32_t __nx_atomic_flag_test_and_set_4(FAR const volatile void *ptr, | ||
int memorder); | ||
uint64_t __nx_atomic_flag_test_and_set_8(FAR const volatile void *ptr, | ||
int memorder); | ||
uint8_t __nx_atomic_fetch_add_1(FAR volatile void *ptr, uint8_t value, | ||
int memorder); | ||
uint16_t __nx_atomic_fetch_add_2(FAR volatile void *ptr, uint16_t value, | ||
int memorder); | ||
uint32_t __nx_atomic_fetch_add_4(FAR volatile void *ptr, uint32_t value, | ||
int memorder); | ||
uint64_t __nx_atomic_fetch_add_8(FAR volatile void *ptr, uint64_t value, | ||
int memorder); | ||
uint8_t __nx_atomic_fetch_sub_1(FAR volatile void *ptr, uint8_t value, | ||
int memorder); | ||
uint16_t __nx_atomic_fetch_sub_2(FAR volatile void *ptr, uint16_t value, | ||
int memorder); | ||
uint32_t __nx_atomic_fetch_sub_4(FAR volatile void *ptr, uint32_t value, | ||
int memorder); | ||
uint64_t __nx_atomic_fetch_sub_8(FAR volatile void *ptr, uint64_t value, | ||
int memorder); | ||
uint8_t __nx_atomic_fetch_and_1(FAR volatile void *ptr, uint8_t value, | ||
int memorder); | ||
uint16_t __nx_atomic_fetch_and_2(FAR volatile void *ptr, uint16_t value, | ||
int memorder); | ||
uint32_t __nx_atomic_fetch_and_4(FAR volatile void *ptr, uint32_t value, | ||
int memorder); | ||
uint64_t __nx_atomic_fetch_and_8(FAR volatile void *ptr, uint64_t value, | ||
int memorder); | ||
uint8_t __nx_atomic_fetch_or_1(FAR volatile void *ptr, uint8_t value, | ||
int memorder); | ||
uint16_t __nx_atomic_fetch_or_2(FAR volatile void *ptr, uint16_t value, | ||
int memorder); | ||
uint32_t __nx_atomic_fetch_or_4(FAR volatile void *ptr, uint32_t value, | ||
int memorder); | ||
uint64_t __nx_atomic_fetch_or_8(FAR volatile void *ptr, uint64_t value, | ||
int memorder); | ||
uint8_t __nx_atomic_fetch_xor_1(FAR volatile void *ptr, uint8_t value, | ||
int memorder); | ||
uint16_t __nx_atomic_fetch_xor_2(FAR volatile void *ptr, uint16_t value, | ||
int memorder); | ||
uint32_t __nx_atomic_fetch_xor_4(FAR volatile void *ptr, uint32_t value, | ||
int memorder); | ||
uint64_t __nx_atomic_fetch_xor_8(FAR volatile void *ptr, uint64_t value, | ||
int memorder); | ||
|
||
#else | ||
|
||
void __atomic_store_1(FAR volatile void *ptr, uint8_t value, int memorder); | ||
void __atomic_store_2(FAR volatile void *ptr, uint16_t value, int memorder); | ||
void __atomic_store_4(FAR volatile void *ptr, uint32_t value, int memorder); | ||
|
@@ -271,4 +461,6 @@ uint32_t __atomic_fetch_xor_4(FAR volatile void *ptr, uint32_t value, | |
uint64_t __atomic_fetch_xor_8(FAR volatile void *ptr, uint64_t value, | ||
int memorder); | ||
|
||
#endif | ||
|
||
#endif /* __INCLUDE_NUTTX_LIB_STDATOMIC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chang ALL
__nx_
tonx_