Fix potential threading issues with resid and residfp.
This commit is contained in:
parent
f3b44f7730
commit
7200229af3
5 changed files with 254 additions and 232 deletions
|
@ -17,6 +17,8 @@
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#define RESID_ENVELOPE_CC
|
#define RESID_ENVELOPE_CC
|
||||||
|
|
||||||
#include "envelope.h"
|
#include "envelope.h"
|
||||||
|
@ -156,18 +158,22 @@ unsigned short EnvelopeGenerator::model_dac[2][1 << 8] = {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Constructor.
|
// Constructor.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
static std::mutex g_class_init_mutex;
|
||||||
|
static bool g_class_init = false;
|
||||||
|
|
||||||
EnvelopeGenerator::EnvelopeGenerator()
|
EnvelopeGenerator::EnvelopeGenerator()
|
||||||
{
|
{
|
||||||
static bool class_init;
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(g_class_init_mutex);
|
||||||
if (!class_init) {
|
if (!g_class_init) {
|
||||||
// Build DAC lookup tables for 8-bit DACs.
|
// Build DAC lookup tables for 8-bit DACs.
|
||||||
// MOS 6581: 2R/R ~ 2.20, missing termination resistor.
|
// MOS 6581: 2R/R ~ 2.20, missing termination resistor.
|
||||||
build_dac_table(model_dac[0], 8, 2.20, false);
|
build_dac_table(model_dac[0], 8, 2.20, false);
|
||||||
// MOS 8580: 2R/R ~ 2.00, correct termination.
|
// MOS 8580: 2R/R ~ 2.00, correct termination.
|
||||||
build_dac_table(model_dac[1], 8, 2.00, true);
|
build_dac_table(model_dac[1], 8, 2.00, true);
|
||||||
|
|
||||||
class_init = true;
|
g_class_init = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_chip_model(MOS6581);
|
set_chip_model(MOS6581);
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#define RESID_FILTER_CC
|
#define RESID_FILTER_CC
|
||||||
|
|
||||||
#ifdef _M_ARM
|
#ifdef _M_ARM
|
||||||
|
@ -191,11 +193,14 @@ Filter::model_filter_t Filter::model_filter[2];
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Constructor.
|
// Constructor.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
static std::mutex g_class_init_mutex;
|
||||||
|
static bool g_class_init = false;
|
||||||
|
|
||||||
Filter::Filter()
|
Filter::Filter()
|
||||||
{
|
{
|
||||||
static bool class_init;
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(g_class_init_mutex);
|
||||||
if (!class_init) {
|
if (!g_class_init) {
|
||||||
// Temporary table for op-amp transfer function.
|
// Temporary table for op-amp transfer function.
|
||||||
int* opamp = new int[1 << 16];
|
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);
|
vcr_n_Ids_term[kVg_Vx] = (unsigned short)(n_Is*log_term*log_term);
|
||||||
}
|
}
|
||||||
|
|
||||||
class_init = true;
|
g_class_init = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enable_filter(true);
|
enable_filter(true);
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#define RESID_WAVE_CC
|
#define RESID_WAVE_CC
|
||||||
|
|
||||||
#include "wave.h"
|
#include "wave.h"
|
||||||
|
@ -60,11 +62,14 @@ unsigned short WaveformGenerator::model_dac[2][1 << 12] = {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Constructor.
|
// Constructor.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
static std::mutex g_class_init_mutex;
|
||||||
|
static bool g_class_init = false;
|
||||||
|
|
||||||
WaveformGenerator::WaveformGenerator()
|
WaveformGenerator::WaveformGenerator()
|
||||||
{
|
{
|
||||||
static bool class_init;
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(g_class_init_mutex);
|
||||||
if (!class_init) {
|
if (!g_class_init) {
|
||||||
// Calculate tables for normal waveforms.
|
// Calculate tables for normal waveforms.
|
||||||
accumulator = 0;
|
accumulator = 0;
|
||||||
for (int i = 0; i < (1 << 12); i++) {
|
for (int i = 0; i < (1 << 12); i++) {
|
||||||
|
@ -89,6 +94,7 @@ WaveformGenerator::WaveformGenerator()
|
||||||
|
|
||||||
class_init = true;
|
class_init = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sync_source = this;
|
sync_source = this;
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,8 @@ short calculateCombinedWaveform(CombinedWaveformConfig config, int waveform, int
|
||||||
|
|
||||||
matrix_t* WaveformCalculator::buildTable(ChipModel model)
|
matrix_t* WaveformCalculator::buildTable(ChipModel model)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(CACHE_LOCK);
|
||||||
|
|
||||||
const CombinedWaveformConfig* cfgArray = config[model == MOS6581 ? 0 : 1];
|
const CombinedWaveformConfig* cfgArray = config[model == MOS6581 ? 0 : 1];
|
||||||
|
|
||||||
cw_cache_t::iterator lb = CACHE.lower_bound(cfgArray);
|
cw_cache_t::iterator lb = CACHE.lower_bound(cfgArray);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#define WAVEFORMCALCULATOR_h
|
#define WAVEFORMCALCULATOR_h
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "siddefs-fp.h"
|
#include "siddefs-fp.h"
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
@ -95,6 +96,7 @@ private:
|
||||||
typedef std::map<const CombinedWaveformConfig*, matrix_t> cw_cache_t;
|
typedef std::map<const CombinedWaveformConfig*, matrix_t> cw_cache_t;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::mutex CACHE_LOCK;
|
||||||
cw_cache_t CACHE;
|
cw_cache_t CACHE;
|
||||||
|
|
||||||
WaveformCalculator() {}
|
WaveformCalculator() {}
|
||||||
|
|
Loading…
Reference in a new issue