Skip to content

Commit 89b4b14

Browse files
committed
Move Atomic.h to <mstd_atomic>
`mbed::Atomic<T>` becomes `mstd::atomic<T>`, alongside the other standard C++ library lookalikes.
1 parent be9aefe commit 89b4b14

File tree

5 files changed

+252
-186
lines changed

5 files changed

+252
-186
lines changed

TESTS/mbed_platform/atomic/main.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "unity/unity.h"
1919
#include "utest/utest.h"
2020

21+
#include <mstd_atomic>
22+
2123
#if !MBED_CONF_RTOS_PRESENT
2224
#error [NOT_SUPPORTED] test not supported
2325
#endif
@@ -28,6 +30,8 @@ using utest::v1::Case;
2830

2931
namespace {
3032

33+
using mstd::atomic;
34+
3135
/* Lock-free operations will be much faster - keep runtime down */
3236
#define ADD_UNLOCKED_ITERATIONS (SystemCoreClock / 1000)
3337
#define ADD_LOCKED_ITERATIONS (SystemCoreClock / 8000)
@@ -53,7 +57,7 @@ struct add_release_incrementer {
5357
static void op(A *ptr)
5458
{
5559
for (long i = add_iterations(*ptr); i > 0; i--) {
56-
ptr->fetch_add(1, mbed::memory_order_release);
60+
ptr->fetch_add(1, mstd::memory_order_release);
5761
}
5862
}
5963
};
@@ -120,8 +124,8 @@ void test_atomic_add()
120124
{
121125
struct {
122126
volatile T nonatomic1;
123-
Atomic<T> atomic1;
124-
volatile Atomic<T> atomic2; // use volatile just to exercise the templates' volatile methods
127+
atomic<T> atomic1;
128+
volatile atomic<T> atomic2; // use volatile just to exercise the templates' volatile methods
125129
volatile T nonatomic2;
126130
} data = { 0, { 0 }, { 1 }, 0 }; // test initialisation
127131

@@ -201,17 +205,17 @@ void struct_incrementer_b(A *data)
201205
template<typename T, size_t N>
202206
void test_atomic_struct()
203207
{
204-
TEST_ASSERT_EQUAL(N, sizeof(Atomic<T>));
208+
TEST_ASSERT_EQUAL(N, sizeof(atomic<T>));
205209

206210
// Small structures don't have value constructor implemented;
207-
Atomic<T> data;
211+
atomic<T> data;
208212
atomic_init(&data, T{0, 0, 0});
209213

210214
Thread t1(osPriorityNormal, THREAD_STACK);
211215
Thread t2(osPriorityNormal, THREAD_STACK);
212216

213-
TEST_ASSERT_EQUAL(osOK, t1.start(callback(struct_incrementer_a<Atomic<T> >, &data)));
214-
TEST_ASSERT_EQUAL(osOK, t2.start(callback(struct_incrementer_b<Atomic<T> >, &data)));
217+
TEST_ASSERT_EQUAL(osOK, t1.start(callback(struct_incrementer_a<atomic<T> >, &data)));
218+
TEST_ASSERT_EQUAL(osOK, t2.start(callback(struct_incrementer_b<atomic<T> >, &data)));
215219

216220
for (long i = add_iterations(data); i > 0; i--) {
217221
T curval = data, newval;

mbed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
#include "platform/mbed_wait_api.h"
9090
#include "platform/mbed_thread.h"
9191
#include "hal/sleep_api.h"
92-
#include "platform/Atomic.h"
92+
#include "platform/mbed_atomic.h"
9393
#include "platform/mbed_power_mgmt.h"
9494
#include "platform/mbed_rtc_time.h"
9595
#include "platform/mbed_poll.h"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __atomic
18+
#define __atomic
19+
20+
// Just go straight to the main file
21+
#include <mstd_atomic>
22+
23+
#define ATOMIC_VAR_INIT(x) { x }
24+
#define ATOMIC_FLAG_INIT MSTD_ATOMIC_FLAG_INIT
25+
26+
// And then pull it all into our std
27+
namespace std {
28+
using mstd::atomic;
29+
using mstd::atomic_is_lock_free;
30+
using mstd::atomic_store;
31+
using mstd::atomic_store_explicit;
32+
using mstd::atomic_load;
33+
using mstd::atomic_load_explicit;
34+
using mstd::atomic_exchange;
35+
using mstd::atomic_exchange_explicit;
36+
using mstd::atomic_compare_exchange_weak;
37+
using mstd::atomic_compare_exchange_weak_explicit;
38+
using mstd::atomic_compare_exchange_strong;
39+
using mstd::atomic_compare_exchange_strong_explicit;
40+
using mstd::atomic_fetch_add;
41+
using mstd::atomic_fetch_add_explicit;
42+
using mstd::atomic_fetch_sub;
43+
using mstd::atomic_fetch_sub_explicit;
44+
using mstd::atomic_fetch_and;
45+
using mstd::atomic_fetch_and_explicit;
46+
using mstd::atomic_fetch_or;
47+
using mstd::atomic_fetch_or_explicit;
48+
using mstd::atomic_fetch_xor;
49+
using mstd::atomic_fetch_xor_explicit;
50+
using mstd::atomic_flag;
51+
using mstd::atomic_flag_test_and_set;
52+
using mstd::atomic_flag_test_and_set_explicit;
53+
using mstd::atomic_flag_clear;
54+
using mstd::atomic_flag_clear_explicit;
55+
using mstd::atomic_init;
56+
using mstd::memory_order;
57+
using mstd::kill_dependency;
58+
using mstd::atomic_thread_fence;
59+
using mstd::atomic_signal_fence;
60+
}
61+
62+
#endif /* __atomic */

0 commit comments

Comments
 (0)