Skip to content

Commit 7afb46b

Browse files
committed
Make atomics less bad;
- Remove horrible stdatomic.h/threads.h shim - Compiler engineers are better at writing atomic/thread stuff than I am - LÖVR requires C11 threads and atomics now - Add /experimental:c11atomics for MSVC support - Requires VS 17.5 preview 2 (ca. 2023) - Use atomics properly everywhere - Any variables used as arguments to atomic_* functions must be atomic - Including refcounts - Compiler warns about this now, which is good - Generally, only use atomic functions when needed - Regular assignment/operators on atomic variables are already atomic - Add thread safe module initialization helper in util, use it everywhere
1 parent 7b4c6b4 commit 7afb46b

File tree

22 files changed

+221
-543
lines changed

22 files changed

+221
-543
lines changed

CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ target_include_directories(lovr PRIVATE
299299
${LOVR_LUA_INCLUDE}
300300
${PROJECT_SOURCE_DIR}/src
301301
${PROJECT_SOURCE_DIR}/src/modules
302-
${PROJECT_SOURCE_DIR}/src/lib/std
303302
${PROJECT_SOURCE_DIR}/etc
304303
)
305304

@@ -653,7 +652,7 @@ endfunction()
653652
if(WIN32)
654653
target_sources(lovr PRIVATE src/core/os_win32.c etc/lovr.rc)
655654
if(MSVC)
656-
set_target_properties(lovr PROPERTIES COMPILE_FLAGS /wd4244)
655+
target_compile_options(lovr PRIVATE /wd4244 /experimental:c11atomics)
657656
# Excuse anonymous union for type punning
658657
set_source_files_properties(src/util.c src/modules/graphics/graphics.c PROPERTIES COMPILE_FLAGS /wd4116)
659658
# Excuse unsigned negation for flag-magic bit math
@@ -669,10 +668,6 @@ if(WIN32)
669668
target_compile_definitions(lovr PRIVATE _CRT_SECURE_NO_WARNINGS)
670669
target_compile_definitions(lovr PRIVATE _CRT_NONSTDC_NO_WARNINGS)
671670

672-
if(MSVC_VERSION VERSION_LESS 1900)
673-
target_compile_definitions(lovr PRIVATE inline=__inline snprintf=_snprintf)
674-
endif()
675-
676671
function(move_dll)
677672
if(TARGET ${ARGV0})
678673
add_custom_command(TARGET move_files POST_BUILD

src/api/l_headset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ int luaopen_lovr_headset(lua_State* L) {
11481148
}
11491149
lua_pop(L, 1);
11501150

1151-
luax_atexit(L, lovrHeadsetDestroy);
11521151
luax_assert(L, lovrHeadsetInit(&config));
1152+
luax_atexit(L, lovrHeadsetDestroy);
11531153
return 1;
11541154
}

src/core/gpu_vk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static struct {
260260
gpu_allocator allocators[GPU_MEMORY_COUNT];
261261
uint8_t allocatorLookup[GPU_MEMORY_COUNT];
262262
gpu_memory memory[1024];
263-
gpu_thread_state* threads;
263+
_Atomic(gpu_thread_state*) threads;
264264
gpu_morgue morgue;
265265
} state;
266266

src/lib/std/stdatomic.h

Lines changed: 0 additions & 177 deletions
This file was deleted.

0 commit comments

Comments
 (0)