Skip to content
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

Fixed typo in incr/decr function #2131

Merged
merged 3 commits into from
Jul 11, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions hal/common/critical.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,6 @@ bool core_util_atomic_cas_u32(uint32_t *ptr, uint32_t *expectedCurrentValue, uin
return success;
}

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)
{
Expand Down Expand Up @@ -269,10 +263,6 @@ 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)
{
Expand Down Expand Up @@ -304,9 +294,21 @@ 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);
#endif


bool core_util_atomic_cas_ptr(void **ptr, void **expectedCurrentValue, void *desiredValue) {
return core_util_atomic_cas_u32(
(uint32_t *)ptr,
(uint32_t *)expectedCurrentValue,
(uint32_t)desiredValue);
}

#endif
void *core_util_atomic_incr_ptr(void **valuePtr, ptrdiff_t delta) {
Copy link
Contributor

@0xc0170 0xc0170 Jul 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cant find stddef.h included within this header to get the ptrdiff_t type, looks like its pulled in by other headers though. btw, why it is ptrdiff_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stddef.h is included in the related header (here) since ptrdiff_t is used in the header.

I wasn't sure what type to use for the second argument, so I just went with what the c++ stdlib used for their atomic operators (here). ssize_t is questionably portable, and ptrdiff_t seems more accurate than intptr_t in this case since you are adding the difference between the pointers.

return (void *)core_util_atomic_incr_u32((uint32_t *)valuePtr, (uint32_t)delta);
}

void *core_util_atomic_decr_ptr(void **valuePtr, ptrdiff_t delta) {
return (void *)core_util_atomic_decr_u32((uint32_t *)valuePtr, (uint32_t)delta);
}