mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
clang 9 compatibility
This commit is contained in:
parent
50b60c025d
commit
efbfc5c8ff
1
.gitignore
vendored
1
.gitignore
vendored
@ -258,3 +258,4 @@ build-test-Desktop_x86_windows_msvc2019_pe_32bit-Debug
|
||||
test/vs2019/.vs
|
||||
Corel Auto-Preserve
|
||||
test/vs2019/Debug No Unit Tests
|
||||
test/kdevelopbuild
|
||||
|
||||
@ -173,7 +173,13 @@ add_executable(etl_tests
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
# atomic is need on Linux with Clang
|
||||
target_link_libraries(etl_tests UnitTest++ atomic)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(etl_tests UnitTest++ atomic Threads::Threads)
|
||||
elseif(NOT UNIX AND APPLE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(etl_tests UnitTest++)
|
||||
else()
|
||||
target_link_libraries(etl_tests UnitTest++)
|
||||
endif()
|
||||
|
||||
@ -63,6 +63,7 @@
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-m32" />
|
||||
<Add option="-lpthread" />
|
||||
</Linker>
|
||||
<ExtraCommands>
|
||||
<Add after="${TARGET_OUTPUT_DIR}${TARGET_OUTPUT_BASENAME}" />
|
||||
@ -97,6 +98,9 @@
|
||||
<Add option="-D_DEBUG" />
|
||||
<Add option="-DETL_NO_STL" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-lpthread" />
|
||||
</Linker>
|
||||
<ExtraCommands>
|
||||
<Add after="${TARGET_OUTPUT_DIR}${TARGET_OUTPUT_BASENAME}" />
|
||||
<Mode after="always" />
|
||||
|
||||
@ -32,6 +32,9 @@ SOFTWARE.
|
||||
#include "etl/atomic/atomic_gcc_sync.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#define REALTIME_TEST 1
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -480,5 +483,44 @@ namespace
|
||||
CHECK_EQUAL(compare_expected, test_expected);
|
||||
CHECK_EQUAL(compare.load(), test.load());
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
#if REALTIME_TEST
|
||||
etl::atomic_int32_t atomic_value = 0U;
|
||||
etl::atomic<int> atomic_flag = false;
|
||||
|
||||
void thread1()
|
||||
{
|
||||
while (!atomic_flag.load());
|
||||
|
||||
for (int i = 0; i < 10000000; ++i)
|
||||
{
|
||||
++atomic_value;
|
||||
}
|
||||
}
|
||||
|
||||
void thread2()
|
||||
{
|
||||
while (!atomic_flag.load());
|
||||
|
||||
for (int i = 0; i < 10000000; ++i)
|
||||
{
|
||||
--atomic_value;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(test_atomic_multi_thread)
|
||||
{
|
||||
std::thread t1(thread1);
|
||||
std::thread t2(thread2);
|
||||
|
||||
atomic_flag.store(true);
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
|
||||
CHECK_EQUAL(0, atomic_value.load());
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
@ -32,6 +32,13 @@ SOFTWARE.
|
||||
#include "etl/atomic/atomic_std.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
#if defined(ETL_TARGET_OS_WINDOWS)
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#define REALTIME_TEST 1
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -480,5 +487,61 @@ namespace
|
||||
CHECK_EQUAL(compare_expected, test_expected);
|
||||
CHECK_EQUAL(compare.load(), test.load());
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
#if REALTIME_TEST
|
||||
|
||||
#if defined(ETL_TARGET_OS_WINDOWS) // Only Windows priority is currently supported
|
||||
#define RAISE_THREAD_PRIORITY SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)
|
||||
#define FIX_PROCESSOR_AFFINITY1 SetThreadAffinityMask(GetCurrentThread(), 1)
|
||||
#define FIX_PROCESSOR_AFFINITY2 SetThreadAffinityMask(GetCurrentThread(), 2)
|
||||
#else
|
||||
#define RAISE_THREAD_PRIORITY
|
||||
#define FIX_PROCESSOR_AFFINITY1
|
||||
#define FIX_PROCESSOR_AFFINITY2
|
||||
#endif
|
||||
|
||||
etl::atomic_int32_t atomic_value = 0U;
|
||||
etl::atomic<int> start = false;
|
||||
|
||||
void thread1()
|
||||
{
|
||||
RAISE_THREAD_PRIORITY;
|
||||
FIX_PROCESSOR_AFFINITY1;
|
||||
|
||||
while (!start.load());
|
||||
|
||||
for (int i = 0; i < 10000000; ++i)
|
||||
{
|
||||
++atomic_value;
|
||||
}
|
||||
}
|
||||
|
||||
void thread2()
|
||||
{
|
||||
RAISE_THREAD_PRIORITY;
|
||||
FIX_PROCESSOR_AFFINITY2;
|
||||
|
||||
while (!start.load());
|
||||
|
||||
for (int i = 0; i < 10000000; ++i)
|
||||
{
|
||||
--atomic_value;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(test_atomic_multi_thread)
|
||||
{
|
||||
std::thread t1(thread1);
|
||||
std::thread t2(thread2);
|
||||
|
||||
start.store(true);
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
|
||||
CHECK_EQUAL(0, atomic_value.load());
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
@ -55,6 +55,7 @@ namespace
|
||||
public:
|
||||
|
||||
Test()
|
||||
: p_controller(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -684,7 +685,8 @@ namespace
|
||||
#define RAISE_THREAD_PRIORITY SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)
|
||||
#define FIX_PROCESSOR_AFFINITY SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
#else
|
||||
#error No thread priority modifier defined
|
||||
#define RAISE_THREAD_PRIORITY
|
||||
#define FIX_PROCESSOR_AFFINITY
|
||||
#endif
|
||||
|
||||
etl::callback_timer<3> controller;
|
||||
|
||||
@ -601,7 +601,8 @@ namespace
|
||||
#define RAISE_THREAD_PRIORITY SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)
|
||||
#define FIX_PROCESSOR_AFFINITY SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
#else
|
||||
#error No thread priority modifier defined
|
||||
#define RAISE_THREAD_PRIORITY
|
||||
#define FIX_PROCESSOR_AFFINITY
|
||||
#endif
|
||||
|
||||
etl::message_timer<3> controller;
|
||||
|
||||
@ -41,7 +41,7 @@ SOFTWARE.
|
||||
|
||||
#if ETL_HAS_MUTEX
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#if defined(ETL_TARGET_OS_WINDOWS)
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ SOFTWARE.
|
||||
|
||||
#if ETL_HAS_MUTEX
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#if defined(ETL_TARGET_OS_WINDOWS)
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ SOFTWARE.
|
||||
|
||||
#if ETL_HAS_ATOMIC
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#if defined(ETL_TARGET_OS_WINDOWS)
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ SOFTWARE.
|
||||
|
||||
#if ETL_HAS_ATOMIC
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#if defined(ETL_TARGET_OS_WINDOWS)
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
@ -571,12 +571,13 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if REALTIME_TEST && defined(ETL_COMPILER_MICROSOFT)
|
||||
#if REALTIME_TEST
|
||||
#if defined(ETL_TARGET_OS_WINDOWS) // Only Windows priority is currently supported
|
||||
#define RAISE_THREAD_PRIORITY SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)
|
||||
#define FIX_PROCESSOR_AFFINITY SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
#else
|
||||
#error No thread priority modifier defined
|
||||
#define RAISE_THREAD_PRIORITY
|
||||
#define FIX_PROCESSOR_AFFINITY
|
||||
#endif
|
||||
|
||||
size_t ticks = 0;
|
||||
|
||||
@ -589,12 +589,13 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if REALTIME_TEST && defined(ETL_COMPILER_MICROSOFT)
|
||||
#if REALTIME_TEST
|
||||
#if defined(ETL_TARGET_OS_WINDOWS) // Only Windows priority is currently supported
|
||||
#define RAISE_THREAD_PRIORITY SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)
|
||||
#define FIX_PROCESSOR_AFFINITY SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
#else
|
||||
#error No thread priority modifier defined
|
||||
#define RAISE_THREAD_PRIORITY
|
||||
#define FIX_PROCESSOR_AFFINITY
|
||||
#endif
|
||||
|
||||
size_t ticks = 0;
|
||||
|
||||
@ -574,12 +574,13 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if REALTIME_TEST && defined(ETL_COMPILER_MICROSOFT)
|
||||
#if REALTIME_TEST
|
||||
#if defined(ETL_TARGET_OS_WINDOWS) // Only Windows priority is currently supported
|
||||
#define RAISE_THREAD_PRIORITY SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)
|
||||
#define FIX_PROCESSOR_AFFINITY SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
#else
|
||||
#error No thread priority modifier defined
|
||||
#define RAISE_THREAD_PRIORITY
|
||||
#define FIX_PROCESSOR_AFFINITY
|
||||
#endif
|
||||
|
||||
size_t ticks = 0;
|
||||
|
||||
@ -34,7 +34,7 @@ SOFTWARE.
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT)
|
||||
#if defined(ETL_TARGET_OS_WINDOWS)
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
@ -591,12 +591,13 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#if REALTIME_TEST && defined(ETL_COMPILER_MICROSOFT)
|
||||
#if defined(ETL_TARGET_OS_WINDOWS) // Only Windows priority is currently supported
|
||||
#if REALTIME_TEST
|
||||
#if defined(ETL_TARGET_OS_WINDOWS) // Only Windows priority is currently supported
|
||||
#define RAISE_THREAD_PRIORITY SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)
|
||||
#define FIX_PROCESSOR_AFFINITY SetThreadAffinityMask(GetCurrentThread(), 1);
|
||||
#else
|
||||
#error No thread priority modifier defined
|
||||
#define RAISE_THREAD_PRIORITY
|
||||
#define FIX_PROCESSOR_AFFINITY
|
||||
#endif
|
||||
|
||||
size_t ticks = 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user