Skip to content

Commit 7778692

Browse files
author
Seppo Takalo
authored
Merge pull request #11039 from kjbracey-arm/mstd
Add <mstd_xxx> C++ headers
2 parents 8006d5f + 852a626 commit 7778692

File tree

39 files changed

+5590
-637
lines changed

39 files changed

+5590
-637
lines changed

.astyleignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
^features/storage/filesystem/littlefs/littlefs/
2121
^features/unsupported/
2222
^hal/storage_abstraction
23+
^platform/cxxsupport
2324
^rtos/TARGET_CORTEX/rtx4
2425
^rtos/TARGET_CORTEX/rtx5
2526
^targets

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;

UNITTESTS/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ set(unittest-includes-base
9595
"${PROJECT_SOURCE_DIR}/target_h/events"
9696
"${PROJECT_SOURCE_DIR}/target_h/events/equeue"
9797
"${PROJECT_SOURCE_DIR}/target_h/platform"
98+
"${PROJECT_SOURCE_DIR}/target_h/platform/cxxsupport"
9899
"${PROJECT_SOURCE_DIR}/target_h/drivers"
99100
"${PROJECT_SOURCE_DIR}/stubs"
100101
"${PROJECT_SOURCE_DIR}/.."
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 MSTD_ALGORITHM_
18+
#define MSTD_ALGORITHM_
19+
20+
/* <mstd_algorithm>
21+
*
22+
* - provides <algorithm>
23+
* - For ARM C 5, standard C++11/14 features:
24+
* - std::min, std::max for std::initializer_list
25+
* - std::all_of, std::any_of, std::none_of
26+
* - std::find_if_not
27+
* - std::equal (2-range forms)
28+
* - std::copy_n, std::move, std::move_backward
29+
* - mstd::min, mstd::max constexpr replacements
30+
*/
31+
32+
#include <algorithm>
33+
34+
namespace mstd {
35+
using std::min;
36+
using std::max;
37+
using std::minmax;
38+
using std::initializer_list;
39+
using std::all_of;
40+
using std::any_of;
41+
using std::none_of;
42+
using std::for_each;
43+
using std::find;
44+
using std::find_if;
45+
using std::find_if_not;
46+
using std::find_end;
47+
using std::find_first_of;
48+
using std::adjacent_find;
49+
using std::count;
50+
using std::count_if;
51+
using std::mismatch;
52+
using std::equal;
53+
using std::search;
54+
using std::search_n;
55+
using std::copy;
56+
using std::copy_n;
57+
using std::copy_if;
58+
using std::move;
59+
using std::move_backward;
60+
using std::swap_ranges;
61+
using std::iter_swap;
62+
using std::transform;
63+
using std::replace;
64+
using std::replace_if;
65+
using std::replace_copy;
66+
using std::replace_copy_if;
67+
using std::fill;
68+
using std::fill_n;
69+
using std::generate;
70+
using std::generate_n;
71+
using std::remove;
72+
using std::remove_if;
73+
using std::remove_copy;
74+
using std::remove_copy_if;
75+
using std::unique;
76+
using std::unique_copy;
77+
using std::reverse;
78+
using std::reverse_copy;
79+
using std::rotate;
80+
using std::rotate_copy;
81+
using std::partition;
82+
using std::stable_partition;
83+
using std::sort;
84+
using std::stable_sort;
85+
using std::partial_sort;
86+
using std::partial_sort_copy;
87+
using std::nth_element;
88+
using std::lower_bound;
89+
using std::upper_bound;
90+
using std::equal_range;
91+
using std::binary_search;
92+
using std::merge;
93+
using std::inplace_merge;
94+
using std::includes;
95+
using std::set_union;
96+
using std::set_intersection;
97+
using std::set_difference;
98+
using std::set_symmetric_difference;
99+
using std::push_heap;
100+
using std::pop_heap;
101+
using std::make_heap;
102+
using std::sort_heap;
103+
using std::min_element;
104+
using std::max_element;
105+
using std::lexicographical_compare;
106+
using std::next_permutation;
107+
using std::prev_permutation;
108+
}
109+
110+
#endif // MSTD_ALGORITHM_
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2017 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+
18+
#ifndef MSTD_ATOMIC_
19+
#define MSTD_ATOMIC_
20+
21+
#include <atomic>
22+
23+
namespace mstd {
24+
using std::atomic;
25+
using std::atomic_is_lock_free;
26+
using std::atomic_store;
27+
using std::atomic_store_explicit;
28+
using std::atomic_load;
29+
using std::atomic_load_explicit;
30+
using std::atomic_exchange;
31+
using std::atomic_exchange_explicit;
32+
using std::atomic_compare_exchange_weak;
33+
using std::atomic_compare_exchange_weak_explicit;
34+
using std::atomic_compare_exchange_strong;
35+
using std::atomic_compare_exchange_strong_explicit;
36+
using std::atomic_fetch_add;
37+
using std::atomic_fetch_add_explicit;
38+
using std::atomic_fetch_sub;
39+
using std::atomic_fetch_sub_explicit;
40+
using std::atomic_fetch_and;
41+
using std::atomic_fetch_and_explicit;
42+
using std::atomic_fetch_or;
43+
using std::atomic_fetch_or_explicit;
44+
using std::atomic_fetch_xor;
45+
using std::atomic_fetch_xor_explicit;
46+
using std::atomic_flag;
47+
using std::atomic_flag_test_and_set;
48+
using std::atomic_flag_test_and_set_explicit;
49+
using std::atomic_flag_clear;
50+
using std::atomic_flag_clear_explicit;
51+
using std::atomic_init;
52+
using std::memory_order;
53+
using std::kill_dependency;
54+
using std::atomic_thread_fence;
55+
using std::atomic_signal_fence;
56+
}
57+
58+
#endif
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 MSTD_CSTDDEF_
18+
#define MSTD_CSTDDEF_
19+
20+
/* <mstd_cstddef>
21+
*
22+
* - provides <cstddef>
23+
* - For ARM C 5, standard C++11/14 features:
24+
* - - adds macro replacements for alignof and alignas keywords
25+
* - - adds missing std::nullptr_t
26+
* - For all toolchains:
27+
* - - MSTD_CONSTEXPR_XX_14 macros that can be used to mark
28+
* things that are valid as constexpr only for C++14 or later,
29+
* permitting constexpr use where ARM C 5 would reject it.
30+
*/
31+
32+
#include <cstddef>
33+
34+
/* Macros that can be used to mark functions and objects that are
35+
* constexpr in C++14 or later, but not in earlier versions.
36+
*/
37+
#if __cplusplus >= 201402
38+
#define MSTD_CONSTEXPR_FN_14 constexpr
39+
#define MSTD_CONSTEXPR_OBJ_14 constexpr
40+
#else
41+
#define MSTD_CONSTEXPR_FN_14 inline
42+
#define MSTD_CONSTEXPR_OBJ_14 const
43+
#endif
44+
45+
namespace mstd
46+
{
47+
using std::size_t;
48+
using std::ptrdiff_t;
49+
using std::nullptr_t;
50+
using std::max_align_t;
51+
52+
}
53+
54+
#endif // MSTD_CSTDDEF_

0 commit comments

Comments
 (0)