sys/atomic_utils: add bit set/clear helpers for unsigned int#21440
Merged
benpicco merged 1 commit intoRIOT-OS:masterfrom Apr 30, 2025
Merged
sys/atomic_utils: add bit set/clear helpers for unsigned int#21440benpicco merged 1 commit intoRIOT-OS:masterfrom
benpicco merged 1 commit intoRIOT-OS:masterfrom
Conversation
maribu
approved these changes
Apr 25, 2025
crasbe
reviewed
Apr 25, 2025
894706c to
94485f6
Compare
maribu
reviewed
Apr 26, 2025
94485f6 to
67b2f56
Compare
maribu
approved these changes
Apr 26, 2025
maribu
reviewed
Apr 26, 2025
sys/include/atomic_utils.h
Outdated
| uint8_t bit) | ||
| { | ||
| #if UINT_MAX == UINT16_MAX | ||
| return atomic_bit_u16(dest, bit); |
Member
There was a problem hiding this comment.
Suggested change
| return atomic_bit_u16(dest, bit); | |
| return atomic_bit_u16((volatile uint16_t *)dest, bit); |
On 16 bit platforms the same issue is with uint16_t, as there both unsigned int and unsigned short are 16 bit and uint16_t can be either.
sys/include/atomic_utils.h
Outdated
| /* Some archs define uint32_t as unsigned long, we need to cast. */ | ||
| return atomic_bit_u32((uint32_t volatile *)dest, bit); | ||
| #else | ||
| return atomic_bit_u64(dest, bit); |
Member
There was a problem hiding this comment.
Suggested change
| return atomic_bit_u64(dest, bit); | |
| return atomic_bit_u64((volatile uint64_t)dest, bit); |
I don't have a practical example, but I do believe that unsigned int, unsigned long, and unsigned long long could in full compliance with the C standard all be 64 bit.
auto-merge was automatically disabled
April 28, 2025 11:25
Head branch was pushed to by a user without write access
67b2f56 to
f7c4917
Compare
auto-merge was automatically disabled
April 28, 2025 13:26
Head branch was pushed to by a user without write access
f7c4917 to
7541ef3
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Contribution description
Add atomic bit set/clear for
unsigned int.Testing procedure
These are just very simple mappings from
unsignedto the fixed size counterparts.No type casting is involvedWith the exceptionatomic_bit_unsigned(), there is no type casting s.t. everything can be checked by the compiler.Issues/PRs references
Completes #21429.