Add add-standard-as-possible version of C++11 <mutex>.
A lot of the stuff in there is generic, but the actual mutex classes and
call_once need to interface with the OS.
For those, they're not available in ARMC5 or IAR; retargetting would be
necessary for ARMC6 and GCC, and I've yet to investigate how whether
that's possible. So for now I'm using local implementations.
Although `Mutex` in principle could support `timed_mutex` and
`recursive_timed_mutex`, we don't have `chrono` for the time parameters,
so hold off for now.
For the generic stuff like mstd::unique_lock, they are aliased to
std::unique_lock where possible.
* Adjust definition to make the default constructor `constexpr`.
This permits use in classes that want lazy initialization and their
own `constexpr` constructor, such as `mstd::mutex`.
* Add `get_no_init()` method to allow an explicit optimisation for
paths that know they won be the first call (such as
`mstd::mutex::unlock`).
* Add `destroy()` method to permit destruction of the contained object.
(`SingletonPtr`'s destructor does not call its destructor - a cheat
to omit destructors of static objects). Needed if using in a class
that needs proper destruction.
Regularise the C++ support glue, adding `<mstd_type_traits>` etc.
These include the base toolchain file, backfill `namespace std` as much
as possible for ARM C 5, and then arrange to create unified
`namespace mstd`, which can incorporate toolchain bypasses
(eg `mstd::swap` for ARM C 5, or `mstd::atomic`), and include local
implementations of post-ARM C++14 stuff.
All APIs in `namespace mstd` are intended to function as their
`namespace std` equivalent, and their presence there indicates they
are functional on all toolchains, and should be safe to use in
an Mbed OS build (including not unreasonable memory footprint).
See README.md for more info.
For all compilers add post-C++14 stuff to namespace mbed:
* invoke, invoke_result, is_invocable, is_invocable_r,
is_nothrow_invocable, is_nothrow_invocable_r, unwrap_reference,
unwrap_ref_decay
For ARM C 5, add C++11 bits based on above to namespace std:
* result_of, reference_wrapper, ref, cref, mem_fn
Revert back to older behaviour where we hold deep sleep lock only while
timing a sleep. Previous version was a speed optimisation, but broke
some tests.
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.
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.
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.
When the function `error` is called without ending in a newline
greentea will not display the error. This is because greentea is
performing line buffering.
This patch ensures that all calls to `error` end with a newline. This
is done by adding an additional newline to end end of the string.
Example code exhibiting this problem:
error("This function is not supported.");
Greentea output before this change:
++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x1001766D
Error Value: 0x0
Current Thread: main Id: 0x8003FD8 Entry: 0x1000E64F StackSize: 0x1000 StackMem: 0x8004AE8 SP: 0x8005898
For more info, visit: https://mbed.com/s/error?error=0x80FF0100&tgt=target
-- MbedOS Error Info --
test suite run finished after 240.50 sec...
Greentea output after this change:
++ MbedOS Error Info ++
Error Status: 0x80FF0100 Code: 256 Module: 255
Error Message: Fatal Run-time error
Location: 0x1001766D
Error Value: 0x0
Current Thread: main Id: 0x8003FD8 Entry: 0x1000E64F StackSize: 0x1000 StackMem: 0x8004AE8 SP: 0x8005898
For more info, visit: https://mbed.com/s/error?error=0x80FF0100&tgt=target
-- MbedOS Error Info --
This function is not supported.
test suite run finished after 240.50 sec...
Static keyword causes problems when trying to use force-inlined
functions from normal inlined functions. This is not legal:
static inline void forced() { }
inline void normal() { forced(); }
You cannot reference internal-linkage things from external-linkage
inline functions.
Removal of the static implies that in C there would need to be a
non-inline definition in case anyone calls it non-inlined, but if the
force attribute is doing its job, that should not happen.
Only significant in-tree user of the MBED_FORCEINLINE macro is
the atomic operations - making this change permits atomic operations
from non-static inline functions.
As we start trying to use new facilities, we're likely to need some more
helpers.
In particular, ARM C 5 has no C++11 support in its library at all, so
to avoid totally breaking it we need some backup.
For the other toolchains, we can add a few C++17/C++20/TS extensions
into namespace mbed to make life a little easier.
* For ARM C 5: C++14 type_traits subset, std::move, std::forward,
std::array, std::initializer_list, std::begin, std::end,
std::align, std::maxalign_t, std::aligned_storage,
alignof + alignas macro replacements.
* For ARM C 5: MBED_CONSTEXPR_FN_14 and MBED_CONSTEXPR_OBJ_14 to
mark things that can only be constexpr in C++14 or later.
* For other compilers: mbed::void_t, mbed::type_identity,
mbed::conjunction, mbed::disjunction, mbed::negation,
mbed::experimental::nonesuch, mbed::experimental::is_detected family,
mbed::remove_cvref, mbed::as_const.
The bulk of Callback.h was auto-generated as 6 specialisations, handling
zero to five arguments.
This can now be handled without specialisation using C++11 variadic
templates, reducing the file from 4,900 lines to 900 lines.
This should reduce compilation time, and offset potential increases from
use of `<type_traits>` or a local `mbed_cxxsupport.h` equivalent.
Several other improvents to `Callback` are possible and/or desirable
with C++11, such as the ability to store lambdas, but this commit is
purely the variadic simplification.
Newer language standards have standard forms for `MBED_NORETURN` and
`MBED_ALIGN` attributes. Use them when available.
C++14 also adds `[[deprecated]]`, but as it needs to go in the middle of
structure definitions as `class [[deprecated]] MyClass`, it's not a
total drop-in-replacemend for `MBED_DEPRECATED`, so that is not
attempted here.
Using standard forms increases the chances that code analysis tools such
Coverity will recognise them - particularly important for "no return".
The `int : 0` bitfield this produced could force integer alignment onto
the structure it was placed in, making a structure that should be 1 byte
be 4 bytes.
Change `int` to `bool` to minimise alignment impact - should be to
nothing.
Alignment/size problem was revealed in a `sizeof` check in an
`Atomic<uint8_t>` test.
M23 doesn't implement Main Extension. So like M0/M0+, these registers HFSR/
MMFSR/BFSR/UFSR/DFSR are not present on M23. Remove access to them in mbed
fault handler for M23 targets.
Use `+ 1` to set the "Thumb" indicator on the `delay_loop` routine
address, rather than `| 1`. That makes it something that can be done
by the linker, rather than needing to be done at run-time.
Saves one instruction and one cycle.
As the timer code became more generic, coping with initialization on
demand, and variable width and speed us_ticker_api implementations,
wait_us has gradually gotten slower and slower.
Some platforms have reportedly seen overhead of wait_us() increase from
10µs to 30µs. These changes should fully reverse that drop, and even
make it better than ever.
Add fast paths for platforms that provide compile-time information about
us_ticker. Speed and code size is improved further if:
* Timer has >= 2^32 microsecond range, or better still is 32-bit 1MHz.
* Platform implements us_ticker_read() as a macro
* Timer is initialised at boot, rather than first use
The latter initialisation option is the default for STM, as this has
always been the case.
Minor tweaks to fix ARM C 5 compatibility.
Pushing "ns_list.h" include to first makes sure "ns_types.h" is included
first, meaning it gets to define `__STDC_LIMIT_MACROS` before the first
include of <stdint.h>, which ensures that UINT8_MAX etc are defined.