-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add Atomic<T> template #10274
Add Atomic<T> template #10274
Conversation
@kjbracey-arm, thank you for your changes. |
@kegilbert @kjbracey-arm
Eg? Is this similar to IE/ie? |
@AnotherButler for the Eg question. As for the ifdef, I'd recommend adding @code around the code segment (adding a review for it). If you'd rather not do that, |
We don't use eg or ie (or any other Latin phrases) in our technical documentation. It can be confusing to readers. |
@kjbracey-arm , please see travis failures |
ba11975
to
a4b7d9c
Compare
Any thoughts on the naming here? To follow general class rules, the top level class is Like |
5a6d374
to
5bba169
Compare
Thinking further on the C++ glue - new proposed scheme:
Thus using For portable (to non-Mbed OS) code, eg for unit tests or module tests, you can use a simple alias to cover both builds:
|
Unit test failure corrected (it was a non-C++14-compatible stub). Rebased. On the discussion about naming/namespaces, that can follow this PR - it can go in now as the current |
CI started |
Test run: FAILEDSummary: 1 of 4 test jobs failed Failed test jobs:
|
Please review unittests |
Adjust some non-C++11-compatible code that failed as a result.
Even though C/C++11 don't offer pre-op forms (that do the operation then return the new value) of their freestanding functions, we will be making them visible via pre-op operators on `Atomic<T>` (++, --, +=, -=, &=, |=, ^=). It is easier to do a pre-op than a post-op, as we can use one fewer register in the assembler, so it's worth optimising for what will be quite common cases. Make these forms accessible for `Atomic<T>`, but don't document them for standalone use at this stage.
Add noexcept for consistency with upcoming Atomic.h
Avoid template ambiguities using type_identity_t. Previously the compiler would be unable to figure out whether uint8_t x; core_util_atomic_store(&x, 0); should invoke core_util_atomic_store<uint8_t>, matching the pointer type, or core_util_atomic_store<int>, matching the value, leading to an ambiguity error. Templates now select only on the type of the atomic pointer parameter.
Add a C++ `Atomic<T>` template to make atomics even easier. Basically compatible with C++11 `std::atomic<T>`, but using the underlying `core_util_atomic_xxx` functions from mbed_atomic.h, so appropriate for synchronising with interrupts and optimised for uniprocessor. One extra piece of functionality beyond the `core_util_atomic_xxx` functions is the ability to have an arbitrary atomic type - eg a small structure with 2 `uint16_t`s can be stored in a `uint32_t` container.
Make the atomic functional test use `Atomic<T>` rather than the standalone functions - this then tests both layers simultaneously.
Another C++14 fix made. Can't do
if That was actually in real cellular code rather than a stub - shows up when unit testing it on x86 with signed |
Test run: FAILEDSummary: 3 of 4 test jobs failed Failed test jobs:
|
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
Add a C++
Atomic<T>
template to make atomics even easier. Basically compatible with C++11std::atomic<T>
, but using the underlyingcore_util_atomic_xxx
functions from mbed_atomic.h, so appropriate for synchronising with interrupts and optimised for uniprocessor.One extra piece of functionality beyond the
core_util_atomic_xxx
functions is the ability to have an arbitrary atomic type - eg a small structure with 2uint16_t
s can be stored in auint32_t
container.Based on
mbed_cxxsupport.h
from #10868.Requires
MBED_STRUCT_STATIC_ASSERT
fix now in #10837Pull request type
Release Notes
Atomic<T>
template to make atomics easier in C++.