RAII collect processor-change signals

This commit is contained in:
Robin Gareus 2020-04-18 23:54:24 +02:00
parent b7c7c02680
commit 9875a95829
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
4 changed files with 30 additions and 19 deletions

View file

@ -653,13 +653,17 @@ public:
{
g_atomic_int_inc (&s->_ignore_route_processor_changes);
}
~ProcessorChangeBlocker () {
~ProcessorChangeBlocker ()
{
if (g_atomic_int_dec_and_test (&_session->_ignore_route_processor_changes)) {
if (g_atomic_int_compare_and_exchange (&_session->_ignored_a_processor_change, 1, 0)) {
if (_reconfigure_on_delete) {
_session->route_processors_changed (RouteProcessorChange ());
}
}
}
}
private:
Session* _session;
bool _reconfigure_on_delete;
@ -2128,6 +2132,7 @@ private:
friend class ProcessorChangeBlocker;
gint _ignore_route_processor_changes; /* atomic */
gint _ignored_a_processor_change;
MidiClockTicker* midi_clock;

View file

@ -314,6 +314,7 @@ Session::Session (AudioEngine &eng,
, _suspend_timecode_transmission (0)
, _speakers (new Speakers)
, _ignore_route_processor_changes (0)
, _ignored_a_processor_change (0)
, midi_clock (0)
, _scene_changer (0)
, _midi_ports (0)

View file

@ -102,8 +102,10 @@ Session::process (pframes_t nframes)
* Route::process_output_buffers() but various functions
* callig it hold a _processor_lock reader-lock
*/
boost::shared_ptr<RouteList> r = routes.reader ();
bool one_or_more_routes_declicking = false;
{
ProcessorChangeBlocker pcb (this);
boost::shared_ptr<RouteList> r = routes.reader ();
for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
if ((*i)->apply_processor_changes_rt()) {
_rt_emit_pending = true;
@ -112,6 +114,7 @@ Session::process (pframes_t nframes)
one_or_more_routes_declicking = true;
}
}
}
if (_rt_emit_pending) {
if (!_rt_thread_active) {
@ -1051,6 +1054,7 @@ Session::emit_route_signals ()
{
// TODO use RAII to allow using these signals in other places
BatchUpdateStart(); /* EMIT SIGNAL */
ProcessorChangeBlocker pcb (this);
boost::shared_ptr<RouteList> r = routes.reader ();
for (RouteList::const_iterator ci = r->begin(); ci != r->end(); ++ci) {
(*ci)->emit_pending_signals ();

View file

@ -1851,6 +1851,7 @@ void
Session::route_processors_changed (RouteProcessorChange c)
{
if (g_atomic_int_get (&_ignore_route_processor_changes) > 0) {
g_atomic_int_set (&_ignored_a_processor_change, 1);
return;
}