mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-03-01 04:55:03 +00:00
Remove utterly useless multithreading switch
Since we're using OpenGL, everything has to be done in the same thread anyways. Besides that, the actual "multithreading" implementation was basically starting an empty thread that did absolutely nothing, then wait synchronously for it to complete and join it on the next frame.
This commit is contained in:
@ -118,7 +118,6 @@ developing libprojectM, trying experimental features or building the library for
|
||||
| CMake option | Default | Required dependencies | Description |
|
||||
|------------------------|---------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `ENABLE_SDL_UI` | `ON` | `SDL2` | Builds the SDL-based test application. Only used for development testing, will not be installed. |
|
||||
| `ENABLE_THREADING` | `ON` | | Enable multithreading support for preset loading if available. |
|
||||
| `ENABLE_INSTALL` | `OFF` | Building as a CMake subproject | Enable projectM install targets when built as a subproject via `add_subdirectory()`. |
|
||||
| `ENABLE_DEBUG_POSTFIX` | `ON` | | Adds `d` (by default) to the name of any binary file in debug builds. |
|
||||
| `ENABLE_SYSTEM_GLM` | `OFF` | | Builds against a system-installed GLM library. |
|
||||
|
||||
@ -64,7 +64,6 @@ cmake_dependent_option(BUILD_SHARED_LIBS "Build and install libprojectM as a sha
|
||||
option(ENABLE_PLAYLIST "Enable building the playlist management library" ON)
|
||||
cmake_dependent_option(ENABLE_SDL_UI "Build the SDL2-based developer test UI" OFF "NOT ENABLE_EMSCRIPTEN" OFF)
|
||||
cmake_dependent_option(ENABLE_GLES "Enable OpenGL ES support" OFF "NOT ENABLE_EMSCRIPTEN AND NOT CMAKE_SYSTEM_NAME STREQUAL Android" ON)
|
||||
cmake_dependent_option(ENABLE_THREADING "Enable multithreading support." ON "NOT ENABLE_EMSCRIPTEN" OFF)
|
||||
option(ENABLE_BOOST_FILESYSTEM "Force the use of boost::filesystem, even if the compiler supports C++17." OFF)
|
||||
cmake_dependent_option(ENABLE_INSTALL "Enable installing projectM libraries and headers." OFF "NOT PROJECT_IS_TOP_LEVEL" ON)
|
||||
option(ENABLE_SYSTEM_GLM "Enable use of system-install GLM library" OFF)
|
||||
@ -118,13 +117,6 @@ if(ENABLE_EMSCRIPTEN)
|
||||
"SHELL:-s NO_DISABLE_EXCEPTION_CATCHING"
|
||||
)
|
||||
|
||||
if(ENABLE_THREADING)
|
||||
message(AUTHOR_WARNING "Threading on emscripten is deemed stable, but may have issues. Use with care.\n"
|
||||
"See https://emscripten.org/docs/porting/pthreads.html for more information.")
|
||||
add_compile_options(-pthread)
|
||||
add_link_options(-pthread)
|
||||
endif()
|
||||
|
||||
set(USE_GLES ON)
|
||||
else()
|
||||
if(ENABLE_SDL_UI)
|
||||
@ -168,12 +160,6 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(ENABLE_THREADING)
|
||||
find_package(Threads REQUIRED)
|
||||
set(PROJECTM_USE_THREADS YES)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(ENABLE_CXX_INTERFACE)
|
||||
@ -216,7 +202,6 @@ message(STATUS "Features:")
|
||||
message(STATUS "==============================================")
|
||||
message(STATUS "")
|
||||
message(STATUS " Build shared libraries: ${BUILD_SHARED_LIBS}")
|
||||
message(STATUS " Threading: ${ENABLE_THREADING}")
|
||||
if(ENABLE_BOOST_FILESYSTEM)
|
||||
message(STATUS " Filesystem support: Boost")
|
||||
message(STATUS " Boost version: ${Boost_VERSION}")
|
||||
|
||||
@ -1,76 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
namespace libprojectM {
|
||||
|
||||
/**
|
||||
* Small class to encapsulate synchronization of a simple background task runner
|
||||
*/
|
||||
class BackgroundWorkerSync
|
||||
{
|
||||
public:
|
||||
BackgroundWorkerSync() = default;
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_isWorkToDo = false;
|
||||
m_finished = false;
|
||||
}
|
||||
|
||||
// called by foreground
|
||||
void WakeUpBackgroundTask()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
m_isWorkToDo = true;
|
||||
m_conditionStartWork.notify_one();
|
||||
}
|
||||
|
||||
// called by foreground
|
||||
void WaitForBackgroundTaskToFinish()
|
||||
{
|
||||
std::unique_lock<std::mutex> guard(m_mutex);
|
||||
while (m_isWorkToDo)
|
||||
{
|
||||
m_conditionWorkDone.wait(guard);
|
||||
}
|
||||
}
|
||||
|
||||
// called by foreground() when shutting down, background thread should exit
|
||||
void FinishUp()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
m_finished = true;
|
||||
m_conditionStartWork.notify_all();
|
||||
}
|
||||
|
||||
// called by background
|
||||
auto WaitForWork() -> bool
|
||||
{
|
||||
std::unique_lock<std::mutex> guard(m_mutex);
|
||||
while (!m_isWorkToDo && !m_finished)
|
||||
{
|
||||
m_conditionStartWork.wait(guard);
|
||||
}
|
||||
return !m_finished;
|
||||
}
|
||||
|
||||
// called by background
|
||||
void FinishedWork()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_mutex);
|
||||
m_isWorkToDo = false;
|
||||
m_conditionWorkDone.notify_one();
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::mutex m_mutex; //!< Mutex that controls access to the work flags.
|
||||
std::condition_variable m_conditionStartWork;
|
||||
std::condition_variable m_conditionWorkDone;
|
||||
volatile bool m_isWorkToDo{ false };
|
||||
volatile bool m_finished{ false };
|
||||
|
||||
};
|
||||
|
||||
} // namespace libprojectM
|
||||
@ -128,13 +128,6 @@ if(ENABLE_INSTALL)
|
||||
)
|
||||
|
||||
if(ENABLE_CXX_INTERFACE)
|
||||
if(ENABLE_THREADING)
|
||||
target_compile_definitions(projectM
|
||||
INTERFACE
|
||||
PROJECTM_USE_THREADS
|
||||
)
|
||||
endif()
|
||||
|
||||
install(FILES
|
||||
Audio/PCM.hpp
|
||||
ProjectM.hpp
|
||||
|
||||
@ -32,27 +32,17 @@
|
||||
#include "Renderer/TextureManager.hpp"
|
||||
#include "Renderer/TransitionShaderManager.hpp"
|
||||
|
||||
#if PROJECTM_USE_THREADS
|
||||
#include "libprojectM/BackgroundWorker.hpp"
|
||||
#endif
|
||||
|
||||
namespace libprojectM {
|
||||
|
||||
ProjectM::ProjectM()
|
||||
: m_presetFactoryManager(std::make_unique<PresetFactoryManager>())
|
||||
#if PROJECTM_USE_THREADS
|
||||
, m_workerSync(std::make_unique<BackgroundWorkerSync>())
|
||||
#endif
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
ProjectM::~ProjectM()
|
||||
{
|
||||
#if PROJECTM_USE_THREADS
|
||||
m_workerSync->FinishUp();
|
||||
m_workerThread.join();
|
||||
#endif
|
||||
// Can't use "=default" in the header due to unique_ptr requiring the actual type declarations.
|
||||
}
|
||||
|
||||
void ProjectM::PresetSwitchRequestedEvent(bool) const
|
||||
@ -113,22 +103,6 @@ void ProjectM::ResetTextures()
|
||||
m_textureManager = std::make_unique<Renderer::TextureManager>(m_textureSearchPaths);
|
||||
}
|
||||
|
||||
#if PROJECTM_USE_THREADS
|
||||
|
||||
void ProjectM::ThreadWorker()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!m_workerSync->WaitForWork())
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_workerSync->FinishedWork();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void ProjectM::RenderFrame()
|
||||
{
|
||||
// Don't render if window area is zero.
|
||||
@ -137,10 +111,6 @@ void ProjectM::RenderFrame()
|
||||
return;
|
||||
}
|
||||
|
||||
#if PROJECTM_USE_THREADS
|
||||
std::lock_guard<std::recursive_mutex> guard(m_presetSwitchMutex);
|
||||
#endif
|
||||
|
||||
// Update FPS and other timer values.
|
||||
m_timeKeeper->UpdateTimers();
|
||||
|
||||
@ -181,12 +151,6 @@ void ProjectM::RenderFrame()
|
||||
|
||||
if (m_timeKeeper->IsSmoothing() && m_transitioningPreset != nullptr)
|
||||
{
|
||||
#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();
|
||||
#endif
|
||||
|
||||
// ToDo: check if new preset is loaded.
|
||||
|
||||
if (m_timeKeeper->SmoothRatio() >= 1.0)
|
||||
@ -256,11 +220,6 @@ void ProjectM::Initialize()
|
||||
|
||||
LoadIdlePreset();
|
||||
|
||||
#if PROJECTM_USE_THREADS
|
||||
m_workerSync->Reset();
|
||||
m_workerThread = std::thread(&ProjectM::ThreadWorker, this);
|
||||
#endif
|
||||
|
||||
m_timeKeeper->StartPreset();
|
||||
}
|
||||
|
||||
|
||||
@ -40,21 +40,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#if PROJECTM_USE_THREADS
|
||||
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#endif
|
||||
|
||||
namespace libprojectM {
|
||||
|
||||
class BackgroundWorkerSync;
|
||||
|
||||
namespace Audio {
|
||||
class BeatDetect;
|
||||
} // namespace Audio
|
||||
|
||||
namespace Renderer {
|
||||
class CopyTexture;
|
||||
class PresetTransition;
|
||||
@ -207,13 +194,6 @@ private:
|
||||
|
||||
auto GetRenderContext() -> Renderer::RenderContext;
|
||||
|
||||
#if PROJECTM_USE_THREADS
|
||||
|
||||
void ThreadWorker();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t m_meshX{32}; //!< Per-point mesh horizontal resolution.
|
||||
uint32_t m_meshY{24}; //!< Per-point mesh vertical resolution.
|
||||
uint32_t m_targetFps{35}; //!< Target frames per second.
|
||||
@ -247,12 +227,6 @@ private:
|
||||
std::unique_ptr<Preset> m_transitioningPreset; //!< Destination preset when smooth preset switching.
|
||||
std::unique_ptr<Renderer::PresetTransition> m_transition; //!< Transition effect used for blending.
|
||||
std::unique_ptr<TimeKeeper> m_timeKeeper; //!< Keeps the different timers used to render and switch presets.
|
||||
|
||||
#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<BackgroundWorkerSync> m_workerSync; //!< Background work synchronizer.
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace libprojectM
|
||||
|
||||
@ -12,9 +12,6 @@ if(NOT "@ENABLE_EMSCRIPTEN@") # ENABLE_EMSCRIPTEN
|
||||
find_dependency(OpenGL)
|
||||
endif()
|
||||
endif()
|
||||
if("@ENABLE_THREADING@") # ENABLE_THREADING
|
||||
find_dependency(Threads)
|
||||
endif()
|
||||
if("@ENABLE_BOOST_FILESYSTEM@") # ENABLE_BOOST_FILESYSTEM
|
||||
find_dependency(Boost COMPONENTS Filesystem)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user