From da8040764f6edbd53292c429b27b64bc21709955 Mon Sep 17 00:00:00 2001 From: Fastigium Date: Tue, 16 Feb 2016 13:27:41 +0100 Subject: [PATCH] Require explicit types when removing PlayHandles in the Mixer This fixes a few deadlocks where a PresetPreviewPlayHandle would be removed by the creation of a new PresetPreviewPlayHandle. --- include/Mixer.h | 2 +- include/PlayHandle.h | 9 ++++----- plugins/GigPlayer/GigPlayer.cpp | 4 +++- plugins/carlabase/carla.cpp | 2 +- plugins/opl2/opl2instrument.cpp | 4 +++- plugins/sf2_player/sf2_player.cpp | 4 +++- plugins/vestige/vestige.cpp | 4 +++- plugins/zynaddsubfx/ZynAddSubFx.cpp | 4 +++- src/core/Mixer.cpp | 4 ++-- src/tracks/BBTrack.cpp | 4 +++- src/tracks/InstrumentTrack.cpp | 5 ++++- src/tracks/SampleTrack.cpp | 2 +- 12 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/Mixer.h b/include/Mixer.h index 3128c65b6..b8d2dec7c 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -224,7 +224,7 @@ public: return m_playHandles; } - void removePlayHandles( Track * _track, bool removeIPHs = true ); + void removePlayHandlesOfTypes( Track * _track, const quint8 types ); bool hasNotePlayHandles(); diff --git a/include/PlayHandle.h b/include/PlayHandle.h index ea66cc65c..73eda3ae5 100644 --- a/include/PlayHandle.h +++ b/include/PlayHandle.h @@ -40,11 +40,10 @@ class PlayHandle : public ThreadableJob public: enum Types { - TypeNotePlayHandle, - TypeInstrumentPlayHandle, - TypeSamplePlayHandle, - TypePresetPreviewHandle, - TypeCount + TypeNotePlayHandle = 0x01, + TypeInstrumentPlayHandle = 0x02, + TypeSamplePlayHandle = 0x04, + TypePresetPreviewHandle = 0x08 } ; typedef Types Type; diff --git a/plugins/GigPlayer/GigPlayer.cpp b/plugins/GigPlayer/GigPlayer.cpp index 1f81f151e..dedfe0ede 100644 --- a/plugins/GigPlayer/GigPlayer.cpp +++ b/plugins/GigPlayer/GigPlayer.cpp @@ -101,7 +101,9 @@ GigInstrument::GigInstrument( InstrumentTrack * _instrument_track ) : GigInstrument::~GigInstrument() { - Engine::mixer()->removePlayHandles( instrumentTrack() ); + Engine::mixer()->removePlayHandlesOfTypes( instrumentTrack(), + PlayHandle::TypeNotePlayHandle + | PlayHandle::TypeInstrumentPlayHandle ); freeInstance(); } diff --git a/plugins/carlabase/carla.cpp b/plugins/carlabase/carla.cpp index de65aa1e3..ad1b683a6 100644 --- a/plugins/carlabase/carla.cpp +++ b/plugins/carlabase/carla.cpp @@ -188,7 +188,7 @@ CarlaInstrument::CarlaInstrument(InstrumentTrack* const instrumentTrack, const D CarlaInstrument::~CarlaInstrument() { - Engine::mixer()->removePlayHandles( instrumentTrack() ); + Engine::mixer()->removePlayHandlesOfTypes(instrumentTrack(), PlayHandle::TypeNotePlayHandle | PlayHandle::TypeInstrumentPlayHandle); if (fHost.resourceDir != NULL) { diff --git a/plugins/opl2/opl2instrument.cpp b/plugins/opl2/opl2instrument.cpp index 46e56eb3d..54493bf92 100644 --- a/plugins/opl2/opl2instrument.cpp +++ b/plugins/opl2/opl2instrument.cpp @@ -217,7 +217,9 @@ opl2instrument::opl2instrument( InstrumentTrack * _instrument_track ) : opl2instrument::~opl2instrument() { delete theEmulator; - Engine::mixer()->removePlayHandles( instrumentTrack() ); + Engine::mixer()->removePlayHandlesOfTypes( instrumentTrack(), + PlayHandle::TypeNotePlayHandle + | PlayHandle::TypeInstrumentPlayHandle ); delete [] renderbuffer; } diff --git a/plugins/sf2_player/sf2_player.cpp b/plugins/sf2_player/sf2_player.cpp index 8d633d6d3..50a39c349 100644 --- a/plugins/sf2_player/sf2_player.cpp +++ b/plugins/sf2_player/sf2_player.cpp @@ -157,7 +157,9 @@ sf2Instrument::sf2Instrument( InstrumentTrack * _instrument_track ) : sf2Instrument::~sf2Instrument() { - Engine::mixer()->removePlayHandles( instrumentTrack() ); + Engine::mixer()->removePlayHandlesOfTypes( instrumentTrack(), + PlayHandle::TypeNotePlayHandle + | PlayHandle::TypeInstrumentPlayHandle ); freeFont(); delete_fluid_synth( m_synth ); delete_fluid_settings( m_settings ); diff --git a/plugins/vestige/vestige.cpp b/plugins/vestige/vestige.cpp index 5ce5f468b..a4836ff93 100644 --- a/plugins/vestige/vestige.cpp +++ b/plugins/vestige/vestige.cpp @@ -102,7 +102,9 @@ vestigeInstrument::~vestigeInstrument() knobFModel = NULL; } - Engine::mixer()->removePlayHandles( instrumentTrack() ); + Engine::mixer()->removePlayHandlesOfTypes( instrumentTrack(), + PlayHandle::TypeNotePlayHandle + | PlayHandle::TypeInstrumentPlayHandle ); closePlugin(); } diff --git a/plugins/zynaddsubfx/ZynAddSubFx.cpp b/plugins/zynaddsubfx/ZynAddSubFx.cpp index 2a9f60224..ad1e8ff90 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.cpp +++ b/plugins/zynaddsubfx/ZynAddSubFx.cpp @@ -144,7 +144,9 @@ ZynAddSubFxInstrument::ZynAddSubFxInstrument( ZynAddSubFxInstrument::~ZynAddSubFxInstrument() { - Engine::mixer()->removePlayHandles( instrumentTrack() ); + Engine::mixer()->removePlayHandlesOfTypes( instrumentTrack(), + PlayHandle::TypeNotePlayHandle + | PlayHandle::TypeInstrumentPlayHandle ); m_pluginMutex.lock(); delete m_plugin; diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index 197440641..92124a660 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -665,13 +665,13 @@ void Mixer::removePlayHandle( PlayHandle * _ph ) -void Mixer::removePlayHandles( Track * _track, bool removeIPHs ) +void Mixer::removePlayHandlesOfTypes( Track * _track, const quint8 types ) { lockPlayHandleRemoval(); PlayHandleList::Iterator it = m_playHandles.begin(); while( it != m_playHandles.end() ) { - if( ( *it )->isFromTrack( _track ) && ( removeIPHs || ( *it )->type() != PlayHandle::TypeInstrumentPlayHandle ) ) + if( ( *it )->isFromTrack( _track ) && ( ( *it )->type() & types ) ) { ( *it )->audioPort()->removePlayHandle( ( *it ) ); if( ( *it )->type() == PlayHandle::TypeNotePlayHandle ) diff --git a/src/tracks/BBTrack.cpp b/src/tracks/BBTrack.cpp index 45210b05f..7b10016bf 100644 --- a/src/tracks/BBTrack.cpp +++ b/src/tracks/BBTrack.cpp @@ -387,7 +387,9 @@ BBTrack::BBTrack( TrackContainer* tc ) : BBTrack::~BBTrack() { - Engine::mixer()->removePlayHandles( this ); + Engine::mixer()->removePlayHandlesOfTypes( this, + PlayHandle::TypeNotePlayHandle + | PlayHandle::TypeInstrumentPlayHandle ); const int bb = s_infoMap[this]; Engine::getBBTrackContainer()->removeBB( bb ); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 545c82c01..e1f7f4b41 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -430,7 +430,10 @@ void InstrumentTrack::silenceAllNotes( bool removeIPH ) lock(); // invalidate all NotePlayHandles linked to this track m_processHandles.clear(); - Engine::mixer()->removePlayHandles( this, removeIPH ); + Engine::mixer()->removePlayHandlesOfTypes( this, removeIPH + ? PlayHandle::TypeNotePlayHandle + | PlayHandle::TypeInstrumentPlayHandle + : PlayHandle::TypeNotePlayHandle ); unlock(); } diff --git a/src/tracks/SampleTrack.cpp b/src/tracks/SampleTrack.cpp index 2f64fd7ef..4858a04dc 100644 --- a/src/tracks/SampleTrack.cpp +++ b/src/tracks/SampleTrack.cpp @@ -446,7 +446,7 @@ SampleTrack::SampleTrack( TrackContainer* tc ) : SampleTrack::~SampleTrack() { - Engine::mixer()->removePlayHandles( this ); + Engine::mixer()->removePlayHandlesOfTypes( this, PlayHandle::TypeSamplePlayHandle ); }