From 2df21a675a1db921f4f52bf581c3b11c149be192 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Thu, 19 May 2016 12:00:41 -0700 Subject: [PATCH] Fix remaining errors, hopefully compiling now. --- .../src/builders/resid-builder/resid/wave.cc | 2 +- .../residfp/FilterModelConfig.cpp | 3 +++ .../residfp/WaveformCalculator.cpp | 16 ++++++++++++++-- .../residfp-builder/residfp/WaveformCalculator.h | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/resid-builder/resid/wave.cc b/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/resid-builder/resid/wave.cc index bdfb4d857..361ee8742 100644 --- a/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/resid-builder/resid/wave.cc +++ b/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/resid-builder/resid/wave.cc @@ -92,7 +92,7 @@ WaveformGenerator::WaveformGenerator() // MOS 8580: 2R/R ~ 2.00, correct termination. build_dac_table(model_dac[1], 12, 2.00, true); - class_init = true; + g_class_init = true; } } diff --git a/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/FilterModelConfig.cpp b/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/FilterModelConfig.cpp index 07ffea58e..affc91445 100644 --- a/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/FilterModelConfig.cpp +++ b/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/FilterModelConfig.cpp @@ -24,6 +24,7 @@ #include #include +#include #include "Integrator.h" #include "OpAmp.h" @@ -90,9 +91,11 @@ const Spline::Point opamp_voltage[OPAMP_SIZE] = }; std::unique_ptr FilterModelConfig::instance(nullptr); +static std::mutex g_FilterModelConfig_mutex; FilterModelConfig* FilterModelConfig::getInstance() { + std::lock_guard guard(g_FilterModelConfig_mutex); if (!instance.get()) { instance.reset(new FilterModelConfig()); diff --git a/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/WaveformCalculator.cpp b/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/WaveformCalculator.cpp index 00ab27aed..7053e8241 100644 --- a/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/WaveformCalculator.cpp +++ b/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/WaveformCalculator.cpp @@ -22,16 +22,28 @@ #include "WaveformCalculator.h" #include +#include namespace reSIDfp { +// Doing it this way somehow prevents race conditions + +std::unique_ptr WaveformCalculator::instance(nullptr); +static std::mutex g_WaveformCalculator_mutex; + WaveformCalculator* WaveformCalculator::getInstance() { - static WaveformCalculator instance; - return &instance; + std::lock_guard guard(g_WaveformCalculator_mutex); + if (!instance.get()) + { + instance.reset(new WaveformCalculator()); + } + + return instance.get(); } + /** * Parameters derived with the Monte Carlo method based on * samplings by kevtris. Code and data available in the project repository [1]. diff --git a/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/WaveformCalculator.h b/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/WaveformCalculator.h index 01b6d46b0..9d13df61b 100644 --- a/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/WaveformCalculator.h +++ b/Frameworks/libsidplay/sidplay-residfp-code/libsidplayfp/src/builders/residfp-builder/residfp/WaveformCalculator.h @@ -92,6 +92,9 @@ typedef struct */ class WaveformCalculator { +private: + static std::unique_ptr instance; + private: typedef std::map cw_cache_t;