Skip to content

Commit 071a983

Browse files
author
John Wellbelove
committed
Added ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE macro and has_atomic_always_lock_free trait
Fixed coditional unit tests in test_atomic
1 parent e478088 commit 071a983

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

include/etl/platform.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,15 @@ SOFTWARE.
434434
#else
435435
#define ETL_HAS_ATOMIC 0
436436
#endif
437+
#if ((ETL_USING_CPP17 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST))) || \
438+
defined(ETL_COMPILER_ARM5) || \
439+
defined(ETL_COMPILER_ARM6) || \
440+
defined(ETL_COMPILER_GCC) || \
441+
defined(ETL_COMPILER_CLANG))
442+
#define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 1
443+
#else
444+
#define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 0
445+
#endif
437446
#endif
438447

439448
//*************************************
@@ -524,6 +533,7 @@ namespace etl
524533
static ETL_CONSTANT bool has_8bit_types = (ETL_USING_8BIT_TYPES == 1);
525534
static ETL_CONSTANT bool has_64bit_types = (ETL_USING_64BIT_TYPES == 1);
526535
static ETL_CONSTANT bool has_atomic = (ETL_HAS_ATOMIC == 1);
536+
static ETL_CONSTANT bool has_atomic_always_lock_free = (ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE == 1);
527537
static ETL_CONSTANT bool has_nullptr = (ETL_HAS_NULLPTR == 1);
528538
static ETL_CONSTANT bool has_char8_t = (ETL_HAS_CHAR8_T == 1);
529539
static ETL_CONSTANT bool has_native_char8_t = (ETL_HAS_NATIVE_CHAR8_T == 1);

test/test_atomic.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ namespace
7676

7777
CHECK_EQUAL(compare.is_lock_free(), test.is_lock_free());
7878

79-
//#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC
80-
// CHECK_TRUE(etl::atomic<int>::is_always_lock_free);
81-
// CHECK_TRUE(test.is_always_lock_free);
82-
//#endif
79+
#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE
80+
CHECK_TRUE(etl::atomic<int>::is_always_lock_free);
81+
CHECK_TRUE(test.is_always_lock_free);
82+
#endif
8383
}
8484

8585
//*************************************************************************
@@ -90,28 +90,28 @@ namespace
9090

9191
CHECK_EQUAL(compare.is_lock_free(), test.is_lock_free());
9292

93-
#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC
93+
#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE
9494
CHECK_TRUE(etl::atomic<int*>::is_always_lock_free);
9595
CHECK_TRUE(test.is_always_lock_free);
9696
#endif
9797
}
9898

99-
//#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC
100-
// //*************************************************************************
101-
// TEST(test_atomic_is_always_lock_free)
102-
// {
103-
// struct S
104-
// {
105-
// int a;
106-
// int b;
107-
// int c;
108-
// };
109-
//
110-
// CHECK_TRUE(etl::atomic<int>::is_always_lock_free);
111-
// CHECK_TRUE(etl::atomic<int*>::is_always_lock_free);
112-
// CHECK_FALSE(etl::atomic<S>::is_always_lock_free);
113-
// }
114-
//#endif
99+
#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE
100+
//*************************************************************************
101+
TEST(test_atomic_is_always_lock_free)
102+
{
103+
struct S
104+
{
105+
int a;
106+
int b;
107+
int c;
108+
};
109+
110+
CHECK_TRUE(etl::atomic<int>::is_always_lock_free);
111+
CHECK_TRUE(etl::atomic<int*>::is_always_lock_free);
112+
CHECK_FALSE(etl::atomic<S>::is_always_lock_free);
113+
}
114+
#endif
115115

116116
//*************************************************************************
117117
TEST(test_atomic_integer_load)

0 commit comments

Comments
 (0)