18
18
#include " unity/unity.h"
19
19
#include " utest/utest.h"
20
20
21
+ #include < mstd_atomic>
22
+
21
23
#if !MBED_CONF_RTOS_PRESENT
22
24
#error [NOT_SUPPORTED] test not supported
23
25
#endif
@@ -28,6 +30,8 @@ using utest::v1::Case;
28
30
29
31
namespace {
30
32
33
+ using mstd::atomic;
34
+
31
35
/* Lock-free operations will be much faster - keep runtime down */
32
36
#define ADD_UNLOCKED_ITERATIONS (SystemCoreClock / 1000 )
33
37
#define ADD_LOCKED_ITERATIONS (SystemCoreClock / 8000 )
@@ -53,7 +57,7 @@ struct add_release_incrementer {
53
57
static void op (A *ptr)
54
58
{
55
59
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);
57
61
}
58
62
}
59
63
};
@@ -120,8 +124,8 @@ void test_atomic_add()
120
124
{
121
125
struct {
122
126
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
125
129
volatile T nonatomic2;
126
130
} data = { 0 , { 0 }, { 1 }, 0 }; // test initialisation
127
131
@@ -201,17 +205,17 @@ void struct_incrementer_b(A *data)
201
205
template <typename T, size_t N>
202
206
void test_atomic_struct ()
203
207
{
204
- TEST_ASSERT_EQUAL (N, sizeof (Atomic <T>));
208
+ TEST_ASSERT_EQUAL (N, sizeof (atomic <T>));
205
209
206
210
// Small structures don't have value constructor implemented;
207
- Atomic <T> data;
211
+ atomic <T> data;
208
212
atomic_init (&data, T{0 , 0 , 0 });
209
213
210
214
Thread t1 (osPriorityNormal, THREAD_STACK);
211
215
Thread t2 (osPriorityNormal, THREAD_STACK);
212
216
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)));
215
219
216
220
for (long i = add_iterations (data); i > 0 ; i--) {
217
221
T curval = data, newval;
0 commit comments