From cf2a074dc0f1949e107c8f5b235000ef7309b01f Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Tue, 27 Aug 2024 15:07:22 +0500 Subject: [PATCH] Fix SDL UI failing to build when C++11 threads are disabled --- CMakeLists.txt | 3 ++- src/CMakeLists.txt | 4 +--- src/qt/CMakeLists.txt | 4 ++++ src/thread.cpp | 12 ++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d5a9dc1e..2766d4921 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,7 +131,6 @@ option(RTMIDI "RtMidi" option(FLUIDSYNTH "FluidSynth" ON) option(MUNT "MUNT" ON) option(VNC "VNC renderer" OFF) -option(CPPTHREADS "C++11 threads" ON) option(NEW_DYNAREC "Use the PCem v15 (\"new\") dynamic recompiler" OFF) option(MINITRACE "Enable Chrome tracing using the modified minitrace library" OFF) option(GDBSTUB "Enable GDB stub server for debugging" OFF) @@ -141,8 +140,10 @@ option(DEBUGREGS486 "Enable debug register opeartion on 486+ CPUs" if(WIN32) set(QT ON) + option(CPPTHREADS "C++11 threads" OFF) else() option(QT "Qt GUI" ON) + option(CPPTHREADS "C++11 threads" ON) endif() # Development branch features diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ad339040f..0841fabdd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,9 +27,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") add_compile_definitions(_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE=1 _LARGEFILE64_SOURCE=1) endif() -if(WIN32) - target_sources(86Box PRIVATE qt/win_thread.c) -else() +if(CPPTHREADS) target_sources(86Box PRIVATE thread.cpp) endif() diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index b3e01c1b9..cf9420a4d 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -227,6 +227,10 @@ if(WIN32 AND NOT MINGW) target_sources(plat PRIVATE win_opendir.c) endif() +if(WIN32 AND NOT CPPTHREADS) + target_sources(plat PRIVATE win_thread.c) +endif() + if(WIN32) target_sources(plat PRIVATE win_serial_passthrough.c win_netsocket.c) else() diff --git a/src/thread.cpp b/src/thread.cpp index 079b80a3e..f2a0ceaf0 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -5,7 +5,7 @@ #include <86box/plat.h> #include <86box/thread.h> -struct event_cpp11_ex_t { +struct event_cpp11_t { std::condition_variable cond; std::mutex mutex; bool state = false; @@ -82,14 +82,14 @@ thread_close_mutex(mutex_t *_mutex) event_t * thread_create_event() { - auto ev = new event_cpp11_ex_t; + auto ev = new event_cpp11_t; return ev; } int thread_wait_event(event_t *handle, int timeout) { - auto event = reinterpret_cast(handle); + auto event = reinterpret_cast(handle); auto lock = std::unique_lock(event->mutex); if (timeout < 0) { @@ -112,7 +112,7 @@ thread_wait_event(event_t *handle, int timeout) void thread_set_event(event_t *handle) { - auto event = reinterpret_cast(handle); + auto event = reinterpret_cast(handle); { auto lock = std::unique_lock(event->mutex); event->state = true; @@ -123,7 +123,7 @@ thread_set_event(event_t *handle) void thread_reset_event(event_t *handle) { - auto event = reinterpret_cast(handle); + auto event = reinterpret_cast(handle); auto lock = std::unique_lock(event->mutex); event->state = false; } @@ -131,7 +131,7 @@ thread_reset_event(event_t *handle) void thread_destroy_event(event_t *handle) { - auto event = reinterpret_cast(handle); + auto event = reinterpret_cast(handle); delete event; } }