Fix potential threading issues with resid and residfp.

This commit is contained in:
Chris Moeller 2016-05-18 20:27:05 -07:00
parent f3b44f7730
commit 7200229af3
5 changed files with 254 additions and 232 deletions

View file

@ -17,6 +17,8 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// ---------------------------------------------------------------------------
#include <mutex>
#define RESID_ENVELOPE_CC
#include "envelope.h"
@ -156,18 +158,22 @@ unsigned short EnvelopeGenerator::model_dac[2][1 << 8] = {
// ----------------------------------------------------------------------------
// Constructor.
// ----------------------------------------------------------------------------
static std::mutex g_class_init_mutex;
static bool g_class_init = false;
EnvelopeGenerator::EnvelopeGenerator()
{
static bool class_init;
if (!class_init) {
{
std::lock_guard<std::mutex> guard(g_class_init_mutex);
if (!g_class_init) {
// Build DAC lookup tables for 8-bit DACs.
// MOS 6581: 2R/R ~ 2.20, missing termination resistor.
build_dac_table(model_dac[0], 8, 2.20, false);
// MOS 8580: 2R/R ~ 2.00, correct termination.
build_dac_table(model_dac[1], 8, 2.00, true);
class_init = true;
g_class_init = true;
}
}
set_chip_model(MOS6581);

View file

@ -17,6 +17,8 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// ---------------------------------------------------------------------------
#include <mutex>
#define RESID_FILTER_CC
#ifdef _M_ARM
@ -191,11 +193,14 @@ Filter::model_filter_t Filter::model_filter[2];
// ----------------------------------------------------------------------------
// Constructor.
// ----------------------------------------------------------------------------
static std::mutex g_class_init_mutex;
static bool g_class_init = false;
Filter::Filter()
{
static bool class_init;
if (!class_init) {
{
std::lock_guard<std::mutex> guard(g_class_init_mutex);
if (!g_class_init) {
// Temporary table for op-amp transfer function.
int* opamp = new int[1 << 16];
@ -415,7 +420,8 @@ Filter::Filter()
vcr_n_Ids_term[kVg_Vx] = (unsigned short)(n_Is*log_term*log_term);
}
class_init = true;
g_class_init = true;
}
}
enable_filter(true);

View file

@ -17,6 +17,8 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// ---------------------------------------------------------------------------
#include <mutex>
#define RESID_WAVE_CC
#include "wave.h"
@ -60,11 +62,14 @@ unsigned short WaveformGenerator::model_dac[2][1 << 12] = {
// ----------------------------------------------------------------------------
// Constructor.
// ----------------------------------------------------------------------------
static std::mutex g_class_init_mutex;
static bool g_class_init = false;
WaveformGenerator::WaveformGenerator()
{
static bool class_init;
if (!class_init) {
{
std::lock_guard<std::mutex> guard(g_class_init_mutex);
if (!g_class_init) {
// Calculate tables for normal waveforms.
accumulator = 0;
for (int i = 0; i < (1 << 12); i++) {
@ -89,6 +94,7 @@ WaveformGenerator::WaveformGenerator()
class_init = true;
}
}
sync_source = this;

View file

@ -172,6 +172,8 @@ short calculateCombinedWaveform(CombinedWaveformConfig config, int waveform, int
matrix_t* WaveformCalculator::buildTable(ChipModel model)
{
std::lock_guard<std::mutex> guard(CACHE_LOCK);
const CombinedWaveformConfig* cfgArray = config[model == MOS6581 ? 0 : 1];
cw_cache_t::iterator lb = CACHE.lower_bound(cfgArray);

View file

@ -23,6 +23,7 @@
#define WAVEFORMCALCULATOR_h
#include <map>
#include <mutex>
#include "siddefs-fp.h"
#include "array.h"
@ -95,6 +96,7 @@ private:
typedef std::map<const CombinedWaveformConfig*, matrix_t> cw_cache_t;
private:
std::mutex CACHE_LOCK;
cw_cache_t CACHE;
WaveformCalculator() {}