-
Notifications
You must be signed in to change notification settings - Fork 3k
Added cas instrinsics for pointer values #2054
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,15 +15,11 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
#define __STDC_LIMIT_MACROS | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include "critical.h" | ||
|
||
#include "cmsis.h" | ||
#include "mbed_assert.h" | ||
|
||
// Module include | ||
#include "critical.h" | ||
|
||
#define EXCLUSIVE_ACCESS (!defined (__CORTEX_M0) && !defined (__CORTEX_M0PLUS)) | ||
|
||
static volatile uint32_t interrupt_enable_counter = 0; | ||
|
@@ -38,7 +34,7 @@ bool core_util_are_interrupts_enabled(void) | |
#endif | ||
} | ||
|
||
void core_util_critical_section_enter() | ||
void core_util_critical_section_enter(void) | ||
{ | ||
bool interrupts_disabled = !core_util_are_interrupts_enabled(); | ||
__disable_irq(); | ||
|
@@ -63,7 +59,7 @@ void core_util_critical_section_enter() | |
interrupt_enable_counter++; | ||
} | ||
|
||
void core_util_critical_section_exit() | ||
void core_util_critical_section_exit(void) | ||
{ | ||
/* If critical_section_enter has not previously been called, do nothing */ | ||
if (interrupt_enable_counter) { | ||
|
@@ -127,7 +123,7 @@ bool core_util_atomic_cas_u32(uint32_t *ptr, uint32_t *expectedCurrentValue, uin | |
return !__STREXW(desiredValue, (volatile uint32_t*)ptr); | ||
} | ||
|
||
uint8_t core_util_atomic_incr_u8(uint8_t * valuePtr, uint8_t delta) | ||
uint8_t core_util_atomic_incr_u8(uint8_t *valuePtr, uint8_t delta) | ||
{ | ||
uint8_t newValue; | ||
do { | ||
|
@@ -136,7 +132,7 @@ uint8_t core_util_atomic_incr_u8(uint8_t * valuePtr, uint8_t delta) | |
return newValue; | ||
} | ||
|
||
uint16_t core_util_atomic_incr_u16(uint16_t * valuePtr, uint16_t delta) | ||
uint16_t core_util_atomic_incr_u16(uint16_t *valuePtr, uint16_t delta) | ||
{ | ||
uint16_t newValue; | ||
do { | ||
|
@@ -145,7 +141,7 @@ uint16_t core_util_atomic_incr_u16(uint16_t * valuePtr, uint16_t delta) | |
return newValue; | ||
} | ||
|
||
uint32_t core_util_atomic_incr_u32(uint32_t * valuePtr, uint32_t delta) | ||
uint32_t core_util_atomic_incr_u32(uint32_t *valuePtr, uint32_t delta) | ||
{ | ||
uint32_t newValue; | ||
do { | ||
|
@@ -155,7 +151,7 @@ uint32_t core_util_atomic_incr_u32(uint32_t * valuePtr, uint32_t delta) | |
} | ||
|
||
|
||
uint8_t core_util_atomic_decr_u8(uint8_t * valuePtr, uint8_t delta) | ||
uint8_t core_util_atomic_decr_u8(uint8_t *valuePtr, uint8_t delta) | ||
{ | ||
uint8_t newValue; | ||
do { | ||
|
@@ -164,7 +160,7 @@ uint8_t core_util_atomic_decr_u8(uint8_t * valuePtr, uint8_t delta) | |
return newValue; | ||
} | ||
|
||
uint16_t core_util_atomic_decr_u16(uint16_t * valuePtr, uint16_t delta) | ||
uint16_t core_util_atomic_decr_u16(uint16_t *valuePtr, uint16_t delta) | ||
{ | ||
uint16_t newValue; | ||
do { | ||
|
@@ -173,7 +169,7 @@ uint16_t core_util_atomic_decr_u16(uint16_t * valuePtr, uint16_t delta) | |
return newValue; | ||
} | ||
|
||
uint32_t core_util_atomic_decr_u32(uint32_t * valuePtr, uint32_t delta) | ||
uint32_t core_util_atomic_decr_u32(uint32_t *valuePtr, uint32_t delta) | ||
{ | ||
uint32_t newValue; | ||
do { | ||
|
@@ -236,7 +232,14 @@ bool core_util_atomic_cas_u32(uint32_t *ptr, uint32_t *expectedCurrentValue, uin | |
return success; | ||
} | ||
|
||
uint8_t core_util_atomic_incr_u8(uint8_t * valuePtr, uint8_t delta) | ||
bool core_util_atomic_cas_ptr(void **ptr, void **expectedCurrentValue, void *desiredValue) { | ||
return core_util_atomic_cas_u32( | ||
(uintptr_t *)ptr, | ||
(uintptr_t *)expectedCurrentValue, | ||
(uintptr_t)desiredValue); | ||
} | ||
|
||
uint8_t core_util_atomic_incr_u8(uint8_t *valuePtr, uint8_t delta) | ||
{ | ||
uint8_t newValue; | ||
core_util_critical_section_enter(); | ||
|
@@ -246,7 +249,7 @@ uint8_t core_util_atomic_incr_u8(uint8_t * valuePtr, uint8_t delta) | |
return newValue; | ||
} | ||
|
||
uint16_t core_util_atomic_incr_u16(uint16_t * valuePtr, uint16_t delta) | ||
uint16_t core_util_atomic_incr_u16(uint16_t *valuePtr, uint16_t delta) | ||
{ | ||
uint16_t newValue; | ||
core_util_critical_section_enter(); | ||
|
@@ -256,7 +259,7 @@ uint16_t core_util_atomic_incr_u16(uint16_t * valuePtr, uint16_t delta) | |
return newValue; | ||
} | ||
|
||
uint32_t core_util_atomic_incr_u32(uint32_t * valuePtr, uint32_t delta) | ||
uint32_t core_util_atomic_incr_u32(uint32_t *valuePtr, uint32_t delta) | ||
{ | ||
uint32_t newValue; | ||
core_util_critical_section_enter(); | ||
|
@@ -266,8 +269,12 @@ uint32_t core_util_atomic_incr_u32(uint32_t * valuePtr, uint32_t delta) | |
return newValue; | ||
} | ||
|
||
void *core_util_atomic_incr_ptr(void **valuePtr, ptrdiff_t delta) { | ||
return core_util_atomic_incr((uintptr_t)valuePtr, (uintptr_t)delta); | ||
} | ||
|
||
|
||
uint8_t core_util_atomic_decr_u8(uint8_t * valuePtr, uint8_t delta) | ||
uint8_t core_util_atomic_decr_u8(uint8_t *valuePtr, uint8_t delta) | ||
{ | ||
uint8_t newValue; | ||
core_util_critical_section_enter(); | ||
|
@@ -277,7 +284,7 @@ uint8_t core_util_atomic_decr_u8(uint8_t * valuePtr, uint8_t delta) | |
return newValue; | ||
} | ||
|
||
uint16_t core_util_atomic_decr_u16(uint16_t * valuePtr, uint16_t delta) | ||
uint16_t core_util_atomic_decr_u16(uint16_t *valuePtr, uint16_t delta) | ||
{ | ||
uint16_t newValue; | ||
core_util_critical_section_enter(); | ||
|
@@ -287,7 +294,7 @@ uint16_t core_util_atomic_decr_u16(uint16_t * valuePtr, uint16_t delta) | |
return newValue; | ||
} | ||
|
||
uint32_t core_util_atomic_decr_u32(uint32_t * valuePtr, uint32_t delta) | ||
uint32_t core_util_atomic_decr_u32(uint32_t *valuePtr, uint32_t delta) | ||
{ | ||
uint32_t newValue; | ||
core_util_critical_section_enter(); | ||
|
@@ -297,5 +304,9 @@ uint32_t core_util_atomic_decr_u32(uint32_t * valuePtr, uint32_t delta) | |
return newValue; | ||
} | ||
|
||
void *core_util_atomic_decr_ptr(void **valuePtr, ptrdiff_t delta) { | ||
return core_util_atomic_decr((uintptr_t)valuePtr, (uintptr_t)delta); | ||
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. Where's |
||
} | ||
|
||
#endif | ||
|
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.
please don't mix unrelated changes. You should submit them in separate pull requests. This is not a matter of convenience.