From bcaf98f2f1e9da3fcdb8b736045615c844f95019 Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Tue, 24 Jan 2023 17:56:12 +0100 Subject: [PATCH] Rename USE_THREADS to PROJECTM_USE_THREADS and export it in the package config file. PROJECTM_USE_THREADS is only exported if ENABLE_CXX_INTERFACE is ON. --- CMakeLists.txt | 2 +- config.h.cmake.in | 4 ++-- src/libprojectM/CMakeLists.txt | 7 +++++++ src/libprojectM/ProjectM.cpp | 14 +++++++------- src/libprojectM/ProjectM.hpp | 6 +++--- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef0bfa08..1a357106f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,7 +161,7 @@ else() if(ENABLE_THREADING) find_package(Threads REQUIRED) - set(USE_THREADS YES) + set(PROJECTM_USE_THREADS YES) endif() if(ENABLE_LLVM) diff --git a/config.h.cmake.in b/config.h.cmake.in index c56b0d1c1..2ce1710b1 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -66,8 +66,8 @@ /* Define USE_GLES */ #cmakedefine01 USE_GLES -/* Define USE_THREADS */ -#cmakedefine01 USE_THREADS +/* Define PROJECTM_USE_THREADS */ +#cmakedefine01 PROJECTM_USE_THREADS /* Version number of package */ #define VERSION "@PROJECT_VERSION@" diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt index af2174772..8f67f907a 100644 --- a/src/libprojectM/CMakeLists.txt +++ b/src/libprojectM/CMakeLists.txt @@ -170,6 +170,13 @@ install(TARGETS projectM ) if(ENABLE_CXX_INTERFACE) + if(ENABLE_THREADING) + target_compile_definitions(projectM + INTERFACE + PROJECTM_USE_THREADS + ) + endif() + set_source_files_properties(ProjectM.cpp PCM.cpp PROPERTIES COMPILE_DEFINITIONS projectM_api_EXPORTS ) diff --git a/src/libprojectM/ProjectM.cpp b/src/libprojectM/ProjectM.cpp index 0d66db825..a7b934fc4 100644 --- a/src/libprojectM/ProjectM.cpp +++ b/src/libprojectM/ProjectM.cpp @@ -30,7 +30,7 @@ #include "Renderer/PipelineContext.hpp" #include "TimeKeeper.hpp" -#if USE_THREADS +#if PROJECTM_USE_THREADS #include "libprojectM/BackgroundWorker.hpp" @@ -40,7 +40,7 @@ ProjectM::ProjectM() : m_presetFactoryManager(std::make_unique()) , m_pipelineContext(std::make_unique()) , m_pipelineContext2(std::make_unique()) -#if USE_THREADS +#if PROJECTM_USE_THREADS , m_workerSync(std::make_unique()) #endif { @@ -49,7 +49,7 @@ ProjectM::ProjectM() ProjectM::~ProjectM() { -#if USE_THREADS +#if PROJECTM_USE_THREADS m_workerSync->FinishUp(); m_workerThread.join(); #endif @@ -120,7 +120,7 @@ void ProjectM::DumpDebugImageOnNextFrame() m_renderer->writeNextFrameToFile = true; } -#if USE_THREADS +#if PROJECTM_USE_THREADS void ProjectM::ThreadWorker() { @@ -166,7 +166,7 @@ void ProjectM::RenderFrame() auto ProjectM::RenderFrameOnlyPass1(Pipeline* pipeline) -> Pipeline* { -#if USE_THREADS +#if PROJECTM_USE_THREADS std::lock_guard guard(m_presetSwitchMutex); #endif @@ -202,7 +202,7 @@ auto ProjectM::RenderFrameOnlyPass1(Pipeline* pipeline) -> Pipeline* if (m_timeKeeper->IsSmoothing() && m_transitioningPreset != nullptr) { -#if USE_THREADS +#if PROJECTM_USE_THREADS m_workerSync->WakeUpBackgroundTask(); // FIXME: Instead of waiting after a single render pass, check every frame if it's done. m_workerSync->WaitForBackgroundTaskToFinish(); @@ -310,7 +310,7 @@ void ProjectM::Initialize() ResetEngine(); LoadIdlePreset(); -#if USE_THREADS +#if PROJECTM_USE_THREADS m_workerSync->Reset(); m_workerThread = std::thread(&ProjectM::ThreadWorker, this); #endif diff --git a/src/libprojectM/ProjectM.hpp b/src/libprojectM/ProjectM.hpp index b2e6d719f..8579989b0 100644 --- a/src/libprojectM/ProjectM.hpp +++ b/src/libprojectM/ProjectM.hpp @@ -39,7 +39,7 @@ #include #include -#if USE_THREADS +#if PROJECTM_USE_THREADS #include #include @@ -240,7 +240,7 @@ private: void LoadIdlePreset(); -#if USE_THREADS +#if PROJECTM_USE_THREADS void ThreadWorker(); @@ -282,7 +282,7 @@ private: std::unique_ptr m_transitioningPreset; //!< Destination preset when smooth preset switching. std::unique_ptr m_timeKeeper; //!< Keeps the different timers used to render and switch presets. -#if USE_THREADS +#if PROJECTM_USE_THREADS mutable std::recursive_mutex m_presetSwitchMutex; //!< Mutex for locking preset switching while rendering and vice versa. std::thread m_workerThread; //!< Background worker for preloading presets. std::unique_ptr m_workerSync; //!< Background work synchronizer.