From cf2311b09f788447d1c079274405477992eee9e8 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 24 Nov 2018 12:29:25 +0100 Subject: Make midnam threadsafe. --- pluginlv2.cc | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'pluginlv2.cc') diff --git a/pluginlv2.cc b/pluginlv2.cc index 6474d5c..d12c0e7 100644 --- a/pluginlv2.cc +++ b/pluginlv2.cc @@ -39,6 +39,15 @@ #include #include +void PluginLV2::init() +{ + for(auto& m : midnamData) + { + m.first = -1; // Mark midnam slot as unsued. + m.second.reserve(64); // Reserve 64 characters for the midnam name. + } +} + bool PluginLV2::getFreeWheel() const { return free_wheel; @@ -363,10 +372,10 @@ void PluginLV2::run(LV2_Handle instance, uint32_t sample_count) plugin_lv2->pos += sample_count; #ifdef MIDNAM_INTERFACE - if(plugin_lv2->midnam && plugin_lv2->midnam_changed) + if(plugin_lv2->midnam && plugin_lv2->midnam_changed.load()) { plugin_lv2->midnam->update(plugin_lv2->midnam->handle); - plugin_lv2->midnam_changed = false; + plugin_lv2->midnam_changed.store(false); } #endif @@ -490,14 +499,17 @@ void PluginLV2::setMidnamData(const std::vector>& mi auto idx = 0u; for(const auto& m : midnam) { - this->midnamData[idx] = m; + midnamData[idx].first = m.first; + // Duplicate name making sure no reallocation is being performed. + midnamData[idx].second = + m.second.substr(0, midnamData[idx].second.capacity() - 1); idx++; } for(;idx < this->midnamData.size(); ++idx) { - this->midnamData[idx] = {-1, {}}; + midnamData[idx].first = -1; // Mark as unused } - midnam_changed = true; + midnam_changed.store(true); } #ifdef MIDNAM_INTERFACE -- cgit v1.2.3