Skip to content

Commit bcb1f0a

Browse files
committed
Improve C11 compiler detection for atomics and related.
1 parent bc2139c commit bcb1f0a

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

cmake/CompileOptions.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ include(Portability)
3434
# Project options
3535
#
3636

37-
# Test for GNU, Clang or ((Visual Studio C++ or Clang with MSVC backend) and Visual Studio 2022 or superior)
38-
if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR
39-
("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR
40-
("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") OR
37+
# Test for GNU 4.9+, Clang 3.6+ or ((Visual Studio C++ or Clang with MSVC backend) and Visual Studio 2022 or superior)
38+
if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND ${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 4.9) OR
39+
((("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR
40+
("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")) AND AND ${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 3.6) OR
4141
(
4242
(("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") OR
4343
(("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") AND ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC"))) AND
4444
(MSVC_VERSION GREATER_EQUAL 1930)
4545
)
4646
)
47-
set(C_STANDARD 11) # TODO: Implement support for older standards
47+
set(C_STANDARD 11)
4848
else()
49-
set(C_STANDARD 99)
49+
set(C_STANDARD 99) # TODO: Implement support for older standards
5050
endif()
5151

5252
set(DEFAULT_PROJECT_OPTIONS

source/threading/include/threading/threading_atomic_win32.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ typedef LONG volatile atomic_flag;
120120
#define atomic_is_lock_free(obj) \
121121
(sizeof(obj) <= 8 && __atomic_is_lock_free_power_of_2(sizeof(obj)))
122122

123+
#undef __atomic_is_lock_free_power_of_2
124+
123125
inline bool atomic_store_explicit8(CHAR volatile *obj, CHAR desired, memory_order order)
124126
{
125127
if (order == memory_order_seq_cst)
@@ -335,6 +337,33 @@ inline bool atomic_compare_exchange64(LONG64 volatile *obj, LONG64 *expected, LO
335337
(sizeof *(obj) == 8) ? _InterlockedAnd64((LONG64 volatile *)obj, (LONG64)(arg)) : \
336338
(abort(), 0))
337339

340+
#define __atomic_compiler_barrier(order) \
341+
do \
342+
{ \
343+
if (order > memory_order_consume) \
344+
{ \
345+
_ReadWriteBarrier(); \
346+
} \
347+
} while (0)
348+
349+
inline void atomic_thread_fence(memory_order order)
350+
{
351+
__atomic_compiler_barrier(order);
352+
353+
if (order == memory_order_seq_cst)
354+
{
355+
MemoryBarrier();
356+
__atomic_compiler_barrier(order);
357+
}
358+
}
359+
360+
inline void atomic_signal_fence(memory_order order)
361+
{
362+
__atomic_compiler_barrier(order);
363+
}
364+
365+
#undef __atomic_compiler_barrier
366+
338367
#ifdef __cplusplus
339368
}
340369
#endif

0 commit comments

Comments
 (0)