Browse Source

replace std::mutex by std::recursive_mutex + protect setProgramChunk() by engine.mutex

pull/1639/head
bsp2 6 years ago
parent
commit
d321f5f150
3 changed files with 18 additions and 9 deletions
  1. +2
    -1
      include/global.hpp
  2. +14
    -7
      src/engine.cpp
  3. +2
    -1
      src/vst2_main.cpp

+ 2
- 1
include/global.hpp View File

@@ -55,7 +55,8 @@ struct Global {
float sampleRate;
float sampleTime;
std::mutex mutex;
// std::mutex mutex;
std::recursive_mutex mutex;
std::thread thread;
VIPMutex vipMutex;


+ 14
- 7
src/engine.cpp View File

@@ -146,7 +146,8 @@ static void engineRun() {
global->engine.vipMutex.wait();

if (!global->gPaused) {
std::lock_guard<std::mutex> lock(global->engine.mutex);
// std::lock_guard<std::mutex> lock(global->engine.mutex);
std::lock_guard<std::recursive_mutex> lock(global->engine.mutex);
for (int i = 0; i < mutexSteps; i++) {
engineStep();
}
@@ -182,7 +183,8 @@ void engineStop() {
void engineAddModule(Module *module) {
assert(module);
VIPLock vipLock(global->engine.vipMutex);
std::lock_guard<std::mutex> lock(global->engine.mutex);
// std::lock_guard<std::mutex> lock(global->engine.mutex);
std::lock_guard<std::recursive_mutex> lock(global->engine.mutex);
// Check that the module is not already added
auto it = std::find(global->gModules.begin(), global->gModules.end(), module);
assert(it == global->gModules.end());
@@ -196,7 +198,8 @@ void engineAddModule(Module *module) {
void engineRemoveModule(Module *module) {
assert(module);
VIPLock vipLock(global->engine.vipMutex);
std::lock_guard<std::mutex> lock(global->engine.mutex);
// std::lock_guard<std::mutex> lock(global->engine.mutex);
std::lock_guard<std::recursive_mutex> lock(global->engine.mutex);
// If a param is being smoothed on this module, stop smoothing it immediately
if (module == global->engine.smoothModule) {
global->engine.smoothModule = NULL;
@@ -233,7 +236,8 @@ static void updateActive() {
void engineAddWire(Wire *wire) {
assert(wire);
VIPLock vipLock(global->engine.vipMutex);
std::lock_guard<std::mutex> lock(global->engine.mutex);
// std::lock_guard<std::mutex> lock(global->engine.mutex);
std::lock_guard<std::recursive_mutex> lock(global->engine.mutex);
// Check wire properties
assert(wire->outputModule);
assert(wire->inputModule);
@@ -250,7 +254,8 @@ void engineAddWire(Wire *wire) {
void engineRemoveWire(Wire *wire) {
assert(wire);
VIPLock vipLock(global->engine.vipMutex);
std::lock_guard<std::mutex> lock(global->engine.mutex);
// std::lock_guard<std::mutex> lock(global->engine.mutex);
std::lock_guard<std::recursive_mutex> lock(global->engine.mutex);
// Check that the wire is already added
auto it = std::find(global->gWires.begin(), global->gWires.end(), wire);
assert(it != global->gWires.end());
@@ -454,7 +459,8 @@ namespace rack {

void engineSetParamSmooth(Module *module, int paramId, float value) {
VIPLock vipLock(global->engine.vipMutex);
std::lock_guard<std::mutex> lock(global->engine.mutex);
// std::lock_guard<std::mutex> lock(global->engine.mutex);
std::lock_guard<std::recursive_mutex> lock(global->engine.mutex);
// Since only one param can be smoothed at a time, if another param is currently being smoothed, skip to its final state
if (global->engine.smoothModule && !(global->engine.smoothModule == module && global->engine.smoothParamId == paramId)) {
global->engine.smoothModule->params[global->engine.smoothParamId].value = global->engine.smoothValue;
@@ -466,7 +472,8 @@ void engineSetParamSmooth(Module *module, int paramId, float value) {

void engineSetSampleRate(float newSampleRate) {
VIPLock vipLock(global->engine.vipMutex);
std::lock_guard<std::mutex> lock(global->engine.mutex);
// std::lock_guard<std::mutex> lock(global->engine.mutex);
std::lock_guard<std::recursive_mutex> lock(global->engine.mutex);
global->engine.sampleRate = newSampleRate;
global->engine.sampleTime = 1.0 / global->engine.sampleRate;
// onSampleRateChange


+ 2
- 1
src/vst2_main.cpp View File

@@ -957,7 +957,6 @@ public:
void setEnableProcessingActive(bool _bEnable) {
lockAudio();
b_processing = _bEnable;

unlockAudio();
}

@@ -1096,6 +1095,8 @@ public:
// Dprintf("xxx vstrack_plugin:setProgramChunk: 3\n");
vst2_set_shared_plugin_tls_globals();
// Dprintf("xxx vstrack_plugin:setProgramChunk: 4\n");
// std::lock_guard<std::mutex> lock(rack::global->engine.mutex);
std::lock_guard<std::recursive_mutex> lock(rack::global->engine.mutex);
#if 0
Dprintf("xxx vstrack_plugin:setProgramChunk: size=%u\n", _size);
#endif


Loading…
Cancel
Save