From 98847b115e4058fe8a6b7185e204003b4c605ce1 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 25 Jan 2021 02:27:46 +0100 Subject: [PATCH] VST3: Allow multiple identical timer-handlers (#8550) Also prefer `const_iterator`, following ``` iterator boost::unordered_map::erase(const_iterator position); ``` --- gtk2_ardour/vst3_x11_plugin_ui.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gtk2_ardour/vst3_x11_plugin_ui.cc b/gtk2_ardour/vst3_x11_plugin_ui.cc index 1eac08f52c..2fa8692835 100644 --- a/gtk2_ardour/vst3_x11_plugin_ui.cc +++ b/gtk2_ardour/vst3_x11_plugin_ui.cc @@ -90,11 +90,11 @@ public: void clear () { Glib::Threads::Mutex::Lock lm (_lock); - for (boost::unordered_map::iterator it = _event_handlers.begin (); it != _event_handlers.end (); ++it) { + for (boost::unordered_map::const_iterator it = _event_handlers.begin (); it != _event_handlers.end (); ++it) { g_source_remove (it->second._source_id); g_io_channel_unref (it->second._gio_channel); } - for (boost::unordered_map::iterator it = _timer_handlers.begin (); it != _timer_handlers.end (); ++it) { + for (boost::unordered_map::const_iterator it = _timer_handlers.begin (); it != _timer_handlers.end (); ++it) { g_source_remove (it->first); } _event_handlers.clear (); @@ -118,9 +118,8 @@ public: } tresult rv = false; - Glib::Threads::Mutex::Lock lm (_lock); - for (boost::unordered_map::iterator it = _event_handlers.begin (); it != _event_handlers.end ();) { + for (boost::unordered_map::const_iterator it = _event_handlers.begin (); it != _event_handlers.end ();) { if (it->second._handler == handler) { g_source_remove (it->second._source_id); g_io_channel_unref (it->second._gio_channel); @@ -151,15 +150,18 @@ public: return kInvalidArgument; } + tresult rv = false; Glib::Threads::Mutex::Lock lm (_lock); - for (boost::unordered_map::iterator it = _timer_handlers.begin (); it != _timer_handlers.end (); ++it) { + for (boost::unordered_map::const_iterator it = _timer_handlers.begin (); it != _timer_handlers.end ();) { if (it->second == handler) { g_source_remove (it->first); - _timer_handlers.erase (it); - return kResultTrue; + it = _timer_handlers.erase (it); + rv = kResultTrue; + } else { + ++it; } } - return kResultFalse; + return rv; } uint32 PLUGIN_API addRef () SMTG_OVERRIDE { return 1; }