Skip to content

Commit 27f3308

Browse files
committed
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.
1 parent 184766b commit 27f3308

7 files changed

+1
-170
lines changed

BUILDING-cmake.md

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ developing libprojectM, trying experimental features or building the library for
118118
| CMake option | Default | Required dependencies | Description |
119119
|------------------------|---------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
120120
| `ENABLE_SDL_UI` | `ON` | `SDL2` | Builds the SDL-based test application. Only used for development testing, will not be installed. |
121-
| `ENABLE_THREADING` | `ON` | | Enable multithreading support for preset loading if available. |
122121
| `ENABLE_INSTALL` | `OFF` | Building as a CMake subproject | Enable projectM install targets when built as a subproject via `add_subdirectory()`. |
123122
| `ENABLE_DEBUG_POSTFIX` | `ON` | | Adds `d` (by default) to the name of any binary file in debug builds. |
124123
| `ENABLE_SYSTEM_GLM` | `OFF` | | Builds against a system-installed GLM library. |

CMakeLists.txt

-15
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ cmake_dependent_option(BUILD_SHARED_LIBS "Build and install libprojectM as a sha
6464
option(ENABLE_PLAYLIST "Enable building the playlist management library" ON)
6565
cmake_dependent_option(ENABLE_SDL_UI "Build the SDL2-based developer test UI" OFF "NOT ENABLE_EMSCRIPTEN" OFF)
6666
cmake_dependent_option(ENABLE_GLES "Enable OpenGL ES support" OFF "NOT ENABLE_EMSCRIPTEN AND NOT CMAKE_SYSTEM_NAME STREQUAL Android" ON)
67-
cmake_dependent_option(ENABLE_THREADING "Enable multithreading support." ON "NOT ENABLE_EMSCRIPTEN" OFF)
6867
option(ENABLE_BOOST_FILESYSTEM "Force the use of boost::filesystem, even if the compiler supports C++17." OFF)
6968
cmake_dependent_option(ENABLE_INSTALL "Enable installing projectM libraries and headers." OFF "NOT PROJECT_IS_TOP_LEVEL" ON)
7069
option(ENABLE_SYSTEM_GLM "Enable use of system-install GLM library" OFF)
@@ -118,13 +117,6 @@ if(ENABLE_EMSCRIPTEN)
118117
"SHELL:-s NO_DISABLE_EXCEPTION_CATCHING"
119118
)
120119

121-
if(ENABLE_THREADING)
122-
message(AUTHOR_WARNING "Threading on emscripten is deemed stable, but may have issues. Use with care.\n"
123-
"See https://emscripten.org/docs/porting/pthreads.html for more information.")
124-
add_compile_options(-pthread)
125-
add_link_options(-pthread)
126-
endif()
127-
128120
set(USE_GLES ON)
129121
else()
130122
if(ENABLE_SDL_UI)
@@ -168,12 +160,6 @@ else()
168160
endif()
169161
endif()
170162
endif()
171-
172-
if(ENABLE_THREADING)
173-
find_package(Threads REQUIRED)
174-
set(PROJECTM_USE_THREADS YES)
175-
endif()
176-
177163
endif()
178164

179165
if(ENABLE_CXX_INTERFACE)
@@ -216,7 +202,6 @@ message(STATUS "Features:")
216202
message(STATUS "==============================================")
217203
message(STATUS "")
218204
message(STATUS " Build shared libraries: ${BUILD_SHARED_LIBS}")
219-
message(STATUS " Threading: ${ENABLE_THREADING}")
220205
if(ENABLE_BOOST_FILESYSTEM)
221206
message(STATUS " Filesystem support: Boost")
222207
message(STATUS " Boost version: ${Boost_VERSION}")

src/libprojectM/BackgroundWorker.hpp

-76
This file was deleted.

src/libprojectM/CMakeLists.txt

-7
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ if(ENABLE_INSTALL)
128128
)
129129

130130
if(ENABLE_CXX_INTERFACE)
131-
if(ENABLE_THREADING)
132-
target_compile_definitions(projectM
133-
INTERFACE
134-
PROJECTM_USE_THREADS
135-
)
136-
endif()
137-
138131
install(FILES
139132
Audio/PCM.hpp
140133
ProjectM.hpp

src/libprojectM/ProjectM.cpp

+1-42
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,17 @@
3232
#include "Renderer/TextureManager.hpp"
3333
#include "Renderer/TransitionShaderManager.hpp"
3434

35-
#if PROJECTM_USE_THREADS
36-
#include "libprojectM/BackgroundWorker.hpp"
37-
#endif
38-
3935
namespace libprojectM {
4036

4137
ProjectM::ProjectM()
4238
: m_presetFactoryManager(std::make_unique<PresetFactoryManager>())
43-
#if PROJECTM_USE_THREADS
44-
, m_workerSync(std::make_unique<BackgroundWorkerSync>())
45-
#endif
4639
{
4740
Initialize();
4841
}
4942

5043
ProjectM::~ProjectM()
5144
{
52-
#if PROJECTM_USE_THREADS
53-
m_workerSync->FinishUp();
54-
m_workerThread.join();
55-
#endif
45+
// Can't use "=default" in the header due to unique_ptr requiring the actual type declarations.
5646
}
5747

5848
void ProjectM::PresetSwitchRequestedEvent(bool) const
@@ -113,22 +103,6 @@ void ProjectM::ResetTextures()
113103
m_textureManager = std::make_unique<Renderer::TextureManager>(m_textureSearchPaths);
114104
}
115105

116-
#if PROJECTM_USE_THREADS
117-
118-
void ProjectM::ThreadWorker()
119-
{
120-
while (true)
121-
{
122-
if (!m_workerSync->WaitForWork())
123-
{
124-
return;
125-
}
126-
m_workerSync->FinishedWork();
127-
}
128-
}
129-
130-
#endif
131-
132106
void ProjectM::RenderFrame()
133107
{
134108
// Don't render if window area is zero.
@@ -137,10 +111,6 @@ void ProjectM::RenderFrame()
137111
return;
138112
}
139113

140-
#if PROJECTM_USE_THREADS
141-
std::lock_guard<std::recursive_mutex> guard(m_presetSwitchMutex);
142-
#endif
143-
144114
// Update FPS and other timer values.
145115
m_timeKeeper->UpdateTimers();
146116

@@ -181,12 +151,6 @@ void ProjectM::RenderFrame()
181151

182152
if (m_timeKeeper->IsSmoothing() && m_transitioningPreset != nullptr)
183153
{
184-
#if PROJECTM_USE_THREADS
185-
m_workerSync->WakeUpBackgroundTask();
186-
// FIXME: Instead of waiting after a single render pass, check every frame if it's done.
187-
m_workerSync->WaitForBackgroundTaskToFinish();
188-
#endif
189-
190154
// ToDo: check if new preset is loaded.
191155

192156
if (m_timeKeeper->SmoothRatio() >= 1.0)
@@ -256,11 +220,6 @@ void ProjectM::Initialize()
256220

257221
LoadIdlePreset();
258222

259-
#if PROJECTM_USE_THREADS
260-
m_workerSync->Reset();
261-
m_workerThread = std::thread(&ProjectM::ThreadWorker, this);
262-
#endif
263-
264223
m_timeKeeper->StartPreset();
265224
}
266225

src/libprojectM/ProjectM.hpp

-26
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,8 @@
4040
#include <string>
4141
#include <vector>
4242

43-
#if PROJECTM_USE_THREADS
44-
45-
#include <mutex>
46-
#include <thread>
47-
48-
#endif
49-
5043
namespace libprojectM {
5144

52-
class BackgroundWorkerSync;
53-
54-
namespace Audio {
55-
class BeatDetect;
56-
} // namespace Audio
57-
5845
namespace Renderer {
5946
class CopyTexture;
6047
class PresetTransition;
@@ -207,13 +194,6 @@ class PROJECTM_EXPORT ProjectM
207194

208195
auto GetRenderContext() -> Renderer::RenderContext;
209196

210-
#if PROJECTM_USE_THREADS
211-
212-
void ThreadWorker();
213-
214-
#endif
215-
216-
217197
uint32_t m_meshX{32}; //!< Per-point mesh horizontal resolution.
218198
uint32_t m_meshY{24}; //!< Per-point mesh vertical resolution.
219199
uint32_t m_targetFps{35}; //!< Target frames per second.
@@ -247,12 +227,6 @@ class PROJECTM_EXPORT ProjectM
247227
std::unique_ptr<Preset> m_transitioningPreset; //!< Destination preset when smooth preset switching.
248228
std::unique_ptr<Renderer::PresetTransition> m_transition; //!< Transition effect used for blending.
249229
std::unique_ptr<TimeKeeper> m_timeKeeper; //!< Keeps the different timers used to render and switch presets.
250-
251-
#if PROJECTM_USE_THREADS
252-
mutable std::recursive_mutex m_presetSwitchMutex; //!< Mutex for locking preset switching while rendering and vice versa.
253-
std::thread m_workerThread; //!< Background worker for preloading presets.
254-
std::unique_ptr<BackgroundWorkerSync> m_workerSync; //!< Background work synchronizer.
255-
#endif
256230
};
257231

258232
} // namespace libprojectM

src/libprojectM/projectM4Config.cmake.in

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ if(NOT "@ENABLE_EMSCRIPTEN@") # ENABLE_EMSCRIPTEN
1212
find_dependency(OpenGL)
1313
endif()
1414
endif()
15-
if("@ENABLE_THREADING@") # ENABLE_THREADING
16-
find_dependency(Threads)
17-
endif()
1815
if("@ENABLE_BOOST_FILESYSTEM@") # ENABLE_BOOST_FILESYSTEM
1916
find_dependency(Boost COMPONENTS Filesystem)
2017
endif()

0 commit comments

Comments
 (0)