diff --git a/TESTS/mbed_platform/atomic/main.cpp b/TESTS/mbed_platform/atomic/main.cpp index 62d7179147..f268d73b4e 100644 --- a/TESTS/mbed_platform/atomic/main.cpp +++ b/TESTS/mbed_platform/atomic/main.cpp @@ -18,6 +18,8 @@ #include "unity/unity.h" #include "utest/utest.h" +#include + #if !MBED_CONF_RTOS_PRESENT #error [NOT_SUPPORTED] test not supported #endif @@ -28,6 +30,8 @@ using utest::v1::Case; namespace { +using mstd::atomic; + /* Lock-free operations will be much faster - keep runtime down */ #define ADD_UNLOCKED_ITERATIONS (SystemCoreClock / 1000) #define ADD_LOCKED_ITERATIONS (SystemCoreClock / 8000) @@ -53,7 +57,7 @@ struct add_release_incrementer { static void op(A *ptr) { for (long i = add_iterations(*ptr); i > 0; i--) { - ptr->fetch_add(1, mbed::memory_order_release); + ptr->fetch_add(1, mstd::memory_order_release); } } }; @@ -120,8 +124,8 @@ void test_atomic_add() { struct { volatile T nonatomic1; - Atomic atomic1; - volatile Atomic atomic2; // use volatile just to exercise the templates' volatile methods + atomic atomic1; + volatile atomic atomic2; // use volatile just to exercise the templates' volatile methods volatile T nonatomic2; } data = { 0, { 0 }, { 1 }, 0 }; // test initialisation @@ -201,17 +205,17 @@ void struct_incrementer_b(A *data) template void test_atomic_struct() { - TEST_ASSERT_EQUAL(N, sizeof(Atomic)); + TEST_ASSERT_EQUAL(N, sizeof(atomic)); // Small structures don't have value constructor implemented; - Atomic data; + atomic data; atomic_init(&data, T{0, 0, 0}); Thread t1(osPriorityNormal, THREAD_STACK); Thread t2(osPriorityNormal, THREAD_STACK); - TEST_ASSERT_EQUAL(osOK, t1.start(callback(struct_incrementer_a >, &data))); - TEST_ASSERT_EQUAL(osOK, t2.start(callback(struct_incrementer_b >, &data))); + TEST_ASSERT_EQUAL(osOK, t1.start(callback(struct_incrementer_a >, &data))); + TEST_ASSERT_EQUAL(osOK, t2.start(callback(struct_incrementer_b >, &data))); for (long i = add_iterations(data); i > 0; i--) { T curval = data, newval; diff --git a/mbed.h b/mbed.h index 3e851b4d36..dc61b2ca8c 100644 --- a/mbed.h +++ b/mbed.h @@ -89,7 +89,7 @@ #include "platform/mbed_wait_api.h" #include "platform/mbed_thread.h" #include "hal/sleep_api.h" -#include "platform/Atomic.h" +#include "platform/mbed_atomic.h" #include "platform/mbed_power_mgmt.h" #include "platform/mbed_rtc_time.h" #include "platform/mbed_poll.h" diff --git a/platform/cxxsupport/TOOLCHAIN_ARMC5/atomic b/platform/cxxsupport/TOOLCHAIN_ARMC5/atomic new file mode 100644 index 0000000000..dbbe759c64 --- /dev/null +++ b/platform/cxxsupport/TOOLCHAIN_ARMC5/atomic @@ -0,0 +1,62 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __atomic +#define __atomic + +// Just go straight to the main file +#include + +#define ATOMIC_VAR_INIT(x) { x } +#define ATOMIC_FLAG_INIT MSTD_ATOMIC_FLAG_INIT + +// And then pull it all into our std +namespace std { +using mstd::atomic; +using mstd::atomic_is_lock_free; +using mstd::atomic_store; +using mstd::atomic_store_explicit; +using mstd::atomic_load; +using mstd::atomic_load_explicit; +using mstd::atomic_exchange; +using mstd::atomic_exchange_explicit; +using mstd::atomic_compare_exchange_weak; +using mstd::atomic_compare_exchange_weak_explicit; +using mstd::atomic_compare_exchange_strong; +using mstd::atomic_compare_exchange_strong_explicit; +using mstd::atomic_fetch_add; +using mstd::atomic_fetch_add_explicit; +using mstd::atomic_fetch_sub; +using mstd::atomic_fetch_sub_explicit; +using mstd::atomic_fetch_and; +using mstd::atomic_fetch_and_explicit; +using mstd::atomic_fetch_or; +using mstd::atomic_fetch_or_explicit; +using mstd::atomic_fetch_xor; +using mstd::atomic_fetch_xor_explicit; +using mstd::atomic_flag; +using mstd::atomic_flag_test_and_set; +using mstd::atomic_flag_test_and_set_explicit; +using mstd::atomic_flag_clear; +using mstd::atomic_flag_clear_explicit; +using mstd::atomic_init; +using mstd::memory_order; +using mstd::kill_dependency; +using mstd::atomic_thread_fence; +using mstd::atomic_signal_fence; +} + +#endif /* __atomic */ diff --git a/platform/Atomic.h b/platform/cxxsupport/mstd_atomic similarity index 76% rename from platform/Atomic.h rename to platform/cxxsupport/mstd_atomic index 63a01d7016..c0a1fe74c0 100644 --- a/platform/Atomic.h +++ b/platform/cxxsupport/mstd_atomic @@ -15,8 +15,8 @@ * limitations under the License. */ -#ifndef MBED_ATOMIC_H -#define MBED_ATOMIC_H +#ifndef MSTD_ATOMIC_ +#define MSTD_ATOMIC_ #include #include @@ -29,7 +29,7 @@ #include "platform/CriticalSectionLock.h" /* - * Atomic template and types are designed to be as close as possible to C++11 + * mstd::atomic template and types are designed to be as close as possible to C++11 * std::atomic. Key differences: * * - Operations are specified as atomic with respect to interrupts as well as @@ -43,34 +43,34 @@ */ #ifndef MBED_EXCLUSIVE_ACCESS -#define MBED_ATOMIC_BOOL_LOCK_FREE 0 -#define MBED_ATOMIC_CHAR_LOCK_FREE 0 -#define MBED_ATOMIC_CHAR16_T_LOCK_FREE 0 -#define MBED_ATOMIC_CHAR32_T_LOCK_FREE 0 -#define MBED_ATOMIC_WCHAR_T_LOCK_FREE 0 -#define MBED_ATOMIC_SHORT_LOCK_FREE 0 -#define MBED_ATOMIC_INT_LOCK_FREE 0 -#define MBED_ATOMIC_LONG_LOCK_FREE 0 -#define MBED_ATOMIC_LLONG_LOCK_FREE 0 -#define MBED_ATOMIC_POINTER_LOCK_FREE 0 +#define MSTD_ATOMIC_BOOL_LOCK_FREE 0 +#define MSTD_ATOMIC_CHAR_LOCK_FREE 0 +#define MSTD_ATOMIC_CHAR16_T_LOCK_FREE 0 +#define MSTD_ATOMIC_CHAR32_T_LOCK_FREE 0 +#define MSTD_ATOMIC_WCHAR_T_LOCK_FREE 0 +#define MSTD_ATOMIC_SHORT_LOCK_FREE 0 +#define MSTD_ATOMIC_INT_LOCK_FREE 0 +#define MSTD_ATOMIC_LONG_LOCK_FREE 0 +#define MSTD_ATOMIC_LLONG_LOCK_FREE 0 +#define MSTD_ATOMIC_POINTER_LOCK_FREE 0 #else -#define MBED_ATOMIC_BOOL_LOCK_FREE 2 -#define MBED_ATOMIC_CHAR_LOCK_FREE 2 -#define MBED_ATOMIC_CHAR16_T_LOCK_FREE 2 -#define MBED_ATOMIC_CHAR32_T_LOCK_FREE 2 -#define MBED_ATOMIC_WCHAR_T_LOCK_FREE 2 -#define MBED_ATOMIC_SHORT_LOCK_FREE 2 -#define MBED_ATOMIC_INT_LOCK_FREE 2 -#define MBED_ATOMIC_LONG_LOCK_FREE 2 -#define MBED_ATOMIC_LLONG_LOCK_FREE 0 -#define MBED_ATOMIC_POINTER_LOCK_FREE 2 +#define MSTD_ATOMIC_BOOL_LOCK_FREE 2 +#define MSTD_ATOMIC_CHAR_LOCK_FREE 2 +#define MSTD_ATOMIC_CHAR16_T_LOCK_FREE 2 +#define MSTD_ATOMIC_CHAR32_T_LOCK_FREE 2 +#define MSTD_ATOMIC_WCHAR_T_LOCK_FREE 2 +#define MSTD_ATOMIC_SHORT_LOCK_FREE 2 +#define MSTD_ATOMIC_INT_LOCK_FREE 2 +#define MSTD_ATOMIC_LONG_LOCK_FREE 2 +#define MSTD_ATOMIC_LLONG_LOCK_FREE 0 +#define MSTD_ATOMIC_POINTER_LOCK_FREE 2 #endif -namespace mbed { +namespace mstd { /** Atomic template * - * `mbed::Atomic` is intended to work as per C++14 `std::atomic`. `T` must be a + * `mstd::atomic` is intended to work as per C++14 `std::atomic`. `T` must be a * _TriviallyCopyable_, _CopyConstructible_ and _CopyAssignable_ type. * - All standard methods of `std::atomic` are supplied: * + For any `T`: `load`, `store`, `exchange`, `compare_exchange_weak`, @@ -85,15 +85,15 @@ namespace mbed { * otherwise critical sections are used. * - If used with large objects, interrupt latency may be impacted. * - Valid initialisation forms are: - * + `Atomic foo;` (zero initialized if static or thread-local, else value indeterminate) + * + `atomic foo;` (zero initialized if static or thread-local, else value indeterminate) * + `atomic_init(&foo, 2);` (initialize a default-initialized variable, once only, not atomic) - * + `Atomic foo(2);` (value initialization) - * + `Atomic foo = { 2 };` (also legal C11 with _Atomic int) - * + `Atomic foo = 2;` (C++17 or later only - also legal C11 with _Atomic int) + * + `atomic foo(2);` (value initialization) + * + `atomic foo = { 2 };` (also legal C11 with _Atomic int) + * + `atomic foo = 2;` (C++17 or later only - also legal C11 with _Atomic int) * Note that the lack of a copy constructor limits the simple-looking assignment initialization * to C++17 or later only. * - The value constructor is not available for small custom types. - * - `MBED_ATOMIC_XXX_LOCK_FREE` replaces `ATOMIC_XXX_LOCK_FREE` - "locking" forms + * - `MSTD_ATOMIC_XXX_LOCK_FREE` replaces `ATOMIC_XXX_LOCK_FREE` - "locking" forms * take a critical section, non-locking do not. * - For `bool`, integer types and pointers, storage is compatible with the * plain types. If necessary, they can be substituted as plain types for C @@ -101,7 +101,7 @@ namespace mbed { * @code * struct foo { * #ifdef __cplusplus - * mbed::atomic_uint32_t counter; // Use C++ templates from C++ code + * mstd::atomic_uint32_t counter; // Use C++ templates from C++ code * #else * uint32_t counter; // Could use core_util_atomic_xxx_u32 from C code, or just have this for structure layout. * #endif @@ -109,9 +109,9 @@ namespace mbed { * @endcode */ template -class Atomic; +class atomic; -/* Pull C enum from mbed_critical.h into mbed namespace */ +/* Pull C enum from mbed_critical.h into mstd namespace */ using memory_order = ::mbed_memory_order; constexpr memory_order memory_order_relaxed = mbed_memory_order_relaxed; constexpr memory_order memory_order_consume = mbed_memory_order_consume; @@ -127,12 +127,12 @@ namespace impl { */ // *INDENT-OFF* template -using atomic_container = std::conditional >>>; +using atomic_container = conditional >>>; // *INDENT-ON* template @@ -142,16 +142,16 @@ template struct atomic_container_is_lock_free; template<> -struct atomic_container_is_lock_free : mstd::bool_constant { }; +struct atomic_container_is_lock_free : bool_constant { }; template<> -struct atomic_container_is_lock_free : mstd::bool_constant { }; +struct atomic_container_is_lock_free : bool_constant { }; template<> -struct atomic_container_is_lock_free : mstd::bool_constant { }; +struct atomic_container_is_lock_free : bool_constant { }; template<> -struct atomic_container_is_lock_free : mstd::bool_constant { }; +struct atomic_container_is_lock_free : bool_constant { }; template using atomic_is_lock_free = atomic_container_is_lock_free>; @@ -571,7 +571,7 @@ protected: /* Template for an integer or pointer Atomic, including increment and * decrement functionality. If StrideT is void, then the increment and - * decrement operators are ill-formed, as desired for Atomic. + * decrement operators are ill-formed, as desired for atomic. */ template> struct AtomicWithAdd : public AtomicBaseInt { @@ -703,15 +703,15 @@ struct AtomicWithBitwise : public AtomicWithAdd { */ // *INDENT-OFF* template -struct AtomicSelector : mstd::type_identity> { }; +struct AtomicSelector : type_identity> { }; template -struct AtomicSelector::value>> - : mstd::type_identity> { }; +struct AtomicSelector::value>> + : type_identity> { }; template -struct AtomicSelector::value && !std::is_same::value>> - : mstd::type_identity> { }; +struct AtomicSelector::value && !is_same::value>> + : type_identity> { }; // *INDENT-ON* template @@ -720,23 +720,23 @@ using Atomic = typename AtomicSelector::type; } // namespace impl template -void atomic_init(volatile Atomic *obj, typename Atomic::value_type desired) noexcept; +void atomic_init(volatile atomic *obj, typename atomic::value_type desired) noexcept; template -void atomic_init(Atomic *obj, typename Atomic::value_type desired) noexcept; +void atomic_init(atomic *obj, typename atomic::value_type desired) noexcept; /* Base template - let impl::Atomic dispatch to raw, base integer or integer-with-bitwise */ template -struct Atomic : public impl::Atomic { +struct atomic : public impl::Atomic { // Constraints from LWG 3012 - static_assert(std::is_trivially_copyable::value, "Atomic types must be TriviallyCopyable"); - static_assert(std::is_copy_constructible::value, "Atomic types must be CopyConstructible"); - static_assert(std::is_move_constructible::value, "Atomic types must be MoveConstructible"); - static_assert(std::is_copy_assignable::value, "Atomic types must be CopyAssignable"); - static_assert(std::is_move_assignable::value, "Atomic types must be MoveAssignable"); - Atomic() noexcept = default; - Atomic(const Atomic &) = delete; - constexpr Atomic(T v) noexcept : impl::Atomic(std::move(v)) + static_assert(is_trivially_copyable::value, "Atomic types must be TriviallyCopyable"); + static_assert(is_copy_constructible::value, "Atomic types must be CopyConstructible"); + static_assert(is_move_constructible::value, "Atomic types must be MoveConstructible"); + static_assert(is_copy_assignable::value, "Atomic types must be CopyAssignable"); + static_assert(is_move_assignable::value, "Atomic types must be MoveAssignable"); + atomic() noexcept = default; + atomic(const atomic &) = delete; + constexpr atomic(T v) noexcept : impl::Atomic(std::move(v)) { } operator T() const volatile noexcept @@ -757,10 +757,10 @@ struct Atomic : public impl::Atomic { this->store(desired); return desired; } - Atomic &operator=(const Atomic &) = delete; + atomic &operator=(const atomic &) = delete; private: - friend void atomic_init<>(volatile Atomic *obj, typename Atomic::value_type desired) noexcept; - friend void atomic_init<>(Atomic *obj, typename Atomic::value_type desired) noexcept; + friend void atomic_init<>(volatile atomic *obj, typename atomic::value_type desired) noexcept; + friend void atomic_init<>(atomic *obj, typename atomic::value_type desired) noexcept; }; @@ -770,10 +770,10 @@ private: * "aptr.load()->member" to use it to access a structure. *aptr is fine though. */ template -struct Atomic : public impl::AtomicWithAdd { - Atomic() noexcept = default; - Atomic(const Atomic &) = delete; - constexpr Atomic(T *v) noexcept : impl::AtomicWithAdd(v) +struct atomic : public impl::AtomicWithAdd { + atomic() noexcept = default; + atomic(const atomic &) = delete; + constexpr atomic(T *v) noexcept : impl::AtomicWithAdd(v) { } operator T *() const volatile noexcept @@ -794,190 +794,190 @@ struct Atomic : public impl::AtomicWithAdd { this->store(desired); return desired; } - Atomic &operator=(const Atomic &) = delete; + atomic &operator=(const atomic &) = delete; private: - friend void atomic_init<>(volatile Atomic *obj, typename Atomic::value_type desired) noexcept; - friend void atomic_init<>(Atomic *obj, typename Atomic::value_type desired) noexcept; + friend void atomic_init<>(volatile atomic *obj, typename atomic::value_type desired) noexcept; + friend void atomic_init<>(atomic *obj, typename atomic::value_type desired) noexcept; }; -using atomic_bool = Atomic; -using atomic_char = Atomic; -using atomic_schar = Atomic; -using atomic_uchar = Atomic; -using atomic_char16_t = Atomic; -using atomic_char32_t = Atomic; -using atomic_wchar_t = Atomic; -using atomic_short = Atomic; -using atomic_ushort = Atomic; -using atomic_int = Atomic; -using atomic_uint = Atomic; -using atomic_long = Atomic; -using atomic_ulong = Atomic; -using atomic_llong = Atomic; -using atomic_ullong = Atomic; -using atomic_int8_t = Atomic; -using atomic_uint8_t = Atomic; -using atomic_int16_t = Atomic; -using atomic_uint16_t = Atomic; -using atomic_int32_t = Atomic; -using atomic_uint32_t = Atomic; -using atomic_int64_t = Atomic; -using atomic_uint64_t = Atomic; -using atomic_int_least8_t = Atomic; -using atomic_uint_least8_t = Atomic; -using atomic_int_least16_t = Atomic; -using atomic_uint_least16_t = Atomic; -using atomic_int_least32_t = Atomic; -using atomic_uint_least32_t = Atomic; -using atomic_int_least64_t = Atomic; -using atomic_uint_least64_t = Atomic; -using atomic_int_fast8_t = Atomic; -using atomic_uint_fast8_t = Atomic; -using atomic_int_fast16_t = Atomic; -using atomic_uint_fast16_t = Atomic; -using atomic_int_fast32_t = Atomic; -using atomic_uint_fast32_t = Atomic; -using atomic_int_fast64_t = Atomic; -using atomic_uint_fast64_t = Atomic; -using atomic_intptr_t = Atomic; -using atomic_uintptr_t = Atomic; -using atomic_size_t = Atomic; -using atomic_ptrdiff_t = Atomic; -using atomic_intmax_t = Atomic; -using atomic_uintmax_t = Atomic; +using atomic_bool = atomic; +using atomic_char = atomic; +using atomic_schar = atomic; +using atomic_uchar = atomic; +using atomic_char16_t = atomic; +using atomic_char32_t = atomic; +using atomic_wchar_t = atomic; +using atomic_short = atomic; +using atomic_ushort = atomic; +using atomic_int = atomic; +using atomic_uint = atomic; +using atomic_long = atomic; +using atomic_ulong = atomic; +using atomic_llong = atomic; +using atomic_ullong = atomic; +using atomic_int8_t = atomic; +using atomic_uint8_t = atomic; +using atomic_int16_t = atomic; +using atomic_uint16_t = atomic; +using atomic_int32_t = atomic; +using atomic_uint32_t = atomic; +using atomic_int64_t = atomic; +using atomic_uint64_t = atomic; +using atomic_int_least8_t = atomic; +using atomic_uint_least8_t = atomic; +using atomic_int_least16_t = atomic; +using atomic_uint_least16_t = atomic; +using atomic_int_least32_t = atomic; +using atomic_uint_least32_t = atomic; +using atomic_int_least64_t = atomic; +using atomic_uint_least64_t = atomic; +using atomic_int_fast8_t = atomic; +using atomic_uint_fast8_t = atomic; +using atomic_int_fast16_t = atomic; +using atomic_uint_fast16_t = atomic; +using atomic_int_fast32_t = atomic; +using atomic_uint_fast32_t = atomic; +using atomic_int_fast64_t = atomic; +using atomic_uint_fast64_t = atomic; +using atomic_intptr_t = atomic; +using atomic_uintptr_t = atomic; +using atomic_size_t = atomic; +using atomic_ptrdiff_t = atomic; +using atomic_intmax_t = atomic; +using atomic_uintmax_t = atomic; template -void atomic_init(Atomic *obj, typename Atomic::value_type desired) noexcept +void atomic_init(atomic *obj, typename atomic::value_type desired) noexcept { obj->init(desired); } template -void atomic_init(volatile Atomic *obj, typename Atomic::value_type desired) noexcept +void atomic_init(volatile atomic *obj, typename atomic::value_type desired) noexcept { obj->init(desired); } template -bool atomic_is_lock_free(const Atomic *obj) noexcept +bool atomic_is_lock_free(const atomic *obj) noexcept { return obj->is_lock_free(); } template -bool atomic_is_lock_free(const volatile Atomic *obj) noexcept +bool atomic_is_lock_free(const volatile atomic *obj) noexcept { return obj->is_lock_free(); } template -void atomic_store(Atomic *obj, typename Atomic::value_type desired) noexcept +void atomic_store(atomic *obj, typename atomic::value_type desired) noexcept { obj->store(desired); } template -void atomic_store(volatile Atomic *obj, typename Atomic::value_type desired) noexcept +void atomic_store(volatile atomic *obj, typename atomic::value_type desired) noexcept { obj->store(desired); } template -void atomic_store_explicit(Atomic *obj, typename Atomic::value_type desired, memory_order order) noexcept +void atomic_store_explicit(atomic *obj, typename atomic::value_type desired, memory_order order) noexcept { obj->store(desired, order); } template -void atomic_store_explicit(volatile Atomic *obj, typename Atomic::value_type desired, memory_order order) noexcept +void atomic_store_explicit(volatile atomic *obj, typename atomic::value_type desired, memory_order order) noexcept { obj->store(desired, order); } template -T atomic_load(const Atomic *obj) noexcept +T atomic_load(const atomic *obj) noexcept { return obj->load(); } template -T atomic_load(const volatile Atomic *obj) noexcept +T atomic_load(const volatile atomic *obj) noexcept { return obj->load(); } template -T atomic_load_explicit(const Atomic *obj, memory_order order) noexcept +T atomic_load_explicit(const atomic *obj, memory_order order) noexcept { return obj->load(order); } template -T atomic_load_explicit(const volatile Atomic *obj, memory_order order) noexcept +T atomic_load_explicit(const volatile atomic *obj, memory_order order) noexcept { return obj->load(order); } template -T atomic_exchange(Atomic *obj, typename Atomic::value_type desired) noexcept +T atomic_exchange(atomic *obj, typename atomic::value_type desired) noexcept { return obj->exchange(desired); } template -T atomic_exchange(volatile Atomic *obj, typename Atomic::value_type desired) noexcept +T atomic_exchange(volatile atomic *obj, typename atomic::value_type desired) noexcept { return obj->exchange(desired); } template -T atomic_exchange_explicit(Atomic *obj, typename Atomic::value_type desired, memory_order order) noexcept +T atomic_exchange_explicit(atomic *obj, typename atomic::value_type desired, memory_order order) noexcept { return obj->exchange(desired, order); } template -T atomic_exchange_explicit(volatile Atomic *obj, typename Atomic::value_type desired, memory_order order) noexcept +T atomic_exchange_explicit(volatile atomic *obj, typename atomic::value_type desired, memory_order order) noexcept { return obj->exchange(desired, order); } template -bool atomic_compare_exchange_weak(Atomic *obj, - typename Atomic::value_type *currentExpected, - typename Atomic::value_type desired) noexcept +bool atomic_compare_exchange_weak(atomic *obj, + typename atomic::value_type *currentExpected, + typename atomic::value_type desired) noexcept { return obj->compare_exchange_weak(obj, *currentExpected, desired); } template -bool atomic_compare_exchange_weak(volatile Atomic *obj, - typename Atomic::value_type *currentExpected, - typename Atomic::value_type desired) noexcept +bool atomic_compare_exchange_weak(volatile atomic *obj, + typename atomic::value_type *currentExpected, + typename atomic::value_type desired) noexcept { return obj->compare_exchange_weak(obj, *currentExpected, desired); } template -bool atomic_compare_exchange_strong(Atomic *obj, - typename Atomic::value_type *currentExpected, - typename Atomic::value_type desired) noexcept +bool atomic_compare_exchange_strong(atomic *obj, + typename atomic::value_type *currentExpected, + typename atomic::value_type desired) noexcept { return obj->compare_exchange_strong(obj, *currentExpected, desired); } template -bool atomic_compare_exchange_strong(volatile Atomic *obj, - typename Atomic::value_type *currentExpected, - typename Atomic::value_type desired) noexcept +bool atomic_compare_exchange_strong(volatile atomic *obj, + typename atomic::value_type *currentExpected, + typename atomic::value_type desired) noexcept { return obj->compare_exchange_strong(obj, *currentExpected, desired); } template -bool atomic_compare_exchange_weak_explicit(Atomic *obj, - typename Atomic::value_type *currentExpected, - typename Atomic::value_type desired, +bool atomic_compare_exchange_weak_explicit(atomic *obj, + typename atomic::value_type *currentExpected, + typename atomic::value_type desired, memory_order success, memory_order failure) noexcept { @@ -985,9 +985,9 @@ bool atomic_compare_exchange_weak_explicit(Atomic *obj, } template -bool atomic_compare_exchange_weak_explicit(volatile Atomic *obj, - typename Atomic::value_type *currentExpected, - typename Atomic::value_type desired, +bool atomic_compare_exchange_weak_explicit(volatile atomic *obj, + typename atomic::value_type *currentExpected, + typename atomic::value_type desired, memory_order success, memory_order failure) noexcept { @@ -995,9 +995,9 @@ bool atomic_compare_exchange_weak_explicit(volatile Atomic *obj, } template -bool atomic_compare_exchange_strong_explicit(Atomic *obj, - typename Atomic::value_type *currentExpected, - typename Atomic::value_type desired, +bool atomic_compare_exchange_strong_explicit(atomic *obj, + typename atomic::value_type *currentExpected, + typename atomic::value_type desired, memory_order success, memory_order failure) noexcept { @@ -1005,9 +1005,9 @@ bool atomic_compare_exchange_strong_explicit(Atomic *obj, } template -bool atomic_compare_exchange_strong_explicit(volatile Atomic *obj, - typename Atomic::value_type *currentExpected, - typename Atomic::value_type desired, +bool atomic_compare_exchange_strong_explicit(volatile atomic *obj, + typename atomic::value_type *currentExpected, + typename atomic::value_type desired, memory_order success, memory_order failure) noexcept { @@ -1015,121 +1015,121 @@ bool atomic_compare_exchange_strong_explicit(volatile Atomic *obj, } template -T atomic_fetch_add(Atomic *obj, typename Atomic::difference_type arg) noexcept +T atomic_fetch_add(atomic *obj, typename atomic::difference_type arg) noexcept { return obj->fetch_add(arg); } template -T atomic_fetch_add(volatile Atomic *obj, typename Atomic::difference_type arg) noexcept +T atomic_fetch_add(volatile atomic *obj, typename atomic::difference_type arg) noexcept { return obj->fetch_add(arg); } template -T atomic_fetch_add_explicit(Atomic *obj, typename Atomic::difference_type arg, memory_order order) noexcept +T atomic_fetch_add_explicit(atomic *obj, typename atomic::difference_type arg, memory_order order) noexcept { return obj->fetch_add(arg, order); } template -T atomic_fetch_add_explicit(volatile Atomic *obj, typename Atomic::difference_type arg, memory_order order) noexcept +T atomic_fetch_add_explicit(volatile atomic *obj, typename atomic::difference_type arg, memory_order order) noexcept { return obj->fetch_add(arg, order); } template -T atomic_fetch_sub(Atomic *obj, typename Atomic::difference_type arg) noexcept +T atomic_fetch_sub(atomic *obj, typename atomic::difference_type arg) noexcept { return obj->fetch_sub(arg); } template -T atomic_fetch_sub(volatile Atomic *obj, typename Atomic::difference_type arg) noexcept +T atomic_fetch_sub(volatile atomic *obj, typename atomic::difference_type arg) noexcept { return obj->fetch_sub(arg); } template -T atomic_fetch_sub_explicit(Atomic *obj, typename Atomic::difference_type arg, memory_order order) noexcept +T atomic_fetch_sub_explicit(atomic *obj, typename atomic::difference_type arg, memory_order order) noexcept { return obj->fetch_sub(arg, order); } template -T atomic_fetch_sub_explicit(volatile Atomic *obj, typename Atomic::difference_type arg, memory_order order) noexcept +T atomic_fetch_sub_explicit(volatile atomic *obj, typename atomic::difference_type arg, memory_order order) noexcept { return obj->fetch_sub(arg, order); } template -T atomic_fetch_and(Atomic *obj, typename Atomic::value_type arg) noexcept +T atomic_fetch_and(atomic *obj, typename atomic::value_type arg) noexcept { return obj->fetch_and(arg); } template -T atomic_fetch_and(volatile Atomic *obj, typename Atomic::value_type arg) noexcept +T atomic_fetch_and(volatile atomic *obj, typename atomic::value_type arg) noexcept { return obj->fetch_and(arg); } template -T atomic_fetch_and_explicit(Atomic *obj, typename Atomic::value_type arg, memory_order order) noexcept +T atomic_fetch_and_explicit(atomic *obj, typename atomic::value_type arg, memory_order order) noexcept { return obj->fetch_and(arg, order); } template -T atomic_fetch_and_explicit(volatile Atomic *obj, typename Atomic::value_type arg, memory_order order) noexcept +T atomic_fetch_and_explicit(volatile atomic *obj, typename atomic::value_type arg, memory_order order) noexcept { return obj->fetch_and(arg, order); } template -T atomic_fetch_or(Atomic *obj, typename Atomic::value_type arg) noexcept +T atomic_fetch_or(atomic *obj, typename atomic::value_type arg) noexcept { return obj->fetch_or(arg); } template -T atomic_fetch_or(volatile Atomic *obj, typename Atomic::value_type arg) noexcept +T atomic_fetch_or(volatile atomic *obj, typename atomic::value_type arg) noexcept { return obj->fetch_or(arg); } template -T atomic_fetch_or_explicit(Atomic *obj, typename Atomic::value_type arg, memory_order order) noexcept +T atomic_fetch_or_explicit(atomic *obj, typename atomic::value_type arg, memory_order order) noexcept { return obj->fetch_or(arg, order); } template -T atomic_fetch_or_explicit(volatile Atomic *obj, typename Atomic::value_type arg, memory_order order) noexcept +T atomic_fetch_or_explicit(volatile atomic *obj, typename atomic::value_type arg, memory_order order) noexcept { return obj->fetch_or(arg, order); } template -T atomic_fetch_xor(Atomic *obj, typename Atomic::value_type arg) noexcept +T atomic_fetch_xor(atomic *obj, typename atomic::value_type arg) noexcept { return obj->fetch_xor(arg); } template -T atomic_fetch_xor(volatile Atomic *obj, typename Atomic::value_type arg) noexcept +T atomic_fetch_xor(volatile atomic *obj, typename atomic::value_type arg) noexcept { return obj->fetch_xor(arg); } template -T atomic_fetch_xor_explicit(Atomic *obj, typename Atomic::value_type arg, memory_order order) noexcept +T atomic_fetch_xor_explicit(atomic *obj, typename atomic::value_type arg, memory_order order) noexcept { return obj->fetch_xor(arg, order); } template -T atomic_fetch_xor_explicit(volatile Atomic *obj, typename Atomic::value_type arg, memory_order order) noexcept +T atomic_fetch_xor_explicit(volatile atomic *obj, typename atomic::value_type arg, memory_order order) noexcept { return obj->fetch_xor(arg, order); } @@ -1207,7 +1207,7 @@ MBED_FORCEINLINE void atomic_flag_clear_explicit(atomic_flag *flag, memory_order flag->clear(order); } -#define MBED_ATOMIC_FLAG_INIT { CORE_UTIL_ATOMIC_FLAG_INIT } +#define MSTD_ATOMIC_FLAG_INIT { CORE_UTIL_ATOMIC_FLAG_INIT } template T kill_dependency(T y) noexcept @@ -1232,6 +1232,6 @@ MBED_FORCEINLINE void atomic_thread_fence(memory_order order) noexcept /**@}*/ -} // namespace mbed +} // namespace mstd #endif diff --git a/platform/internal/mbed_atomic_impl.h b/platform/internal/mbed_atomic_impl.h index 05c3f135b0..171a00c293 100644 --- a/platform/internal/mbed_atomic_impl.h +++ b/platform/internal/mbed_atomic_impl.h @@ -1338,7 +1338,7 @@ DO_MBED_ATOMIC_OP_U_TEMPLATES(fetch_and) DO_MBED_ATOMIC_OP_U_TEMPLATES(fetch_or) DO_MBED_ATOMIC_OP_U_TEMPLATES(fetch_xor) -namespace mbed { +namespace mstd { namespace impl { // Use custom assembler forms for pre-ops where available, else construct from post-ops