From 624d25b8c3e9bd1648fdadbe28e1859cecab494f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 22 May 2016 16:44:11 +0200 Subject: Explicitly stop the loader thread to ensure we don't delete the DrumGizmo::drumkit member while the loader is attached to it. --- src/drumkitloader.cc | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'src/drumkitloader.cc') diff --git a/src/drumkitloader.cc b/src/drumkitloader.cc index 814a98d..94daf79 100644 --- a/src/drumkitloader.cc +++ b/src/drumkitloader.cc @@ -45,21 +45,34 @@ DrumKitLoader::DrumKitLoader(Settings& settings, DrumKit& kit, , resamplers(resamplers) , rand(rand) { - run(); - run_semaphore.wait(); // Wait for the thread to actually start. } DrumKitLoader::~DrumKitLoader() { - DEBUG(loader, "~DrumKitLoader() pre\n"); + assert(!running); +} +void DrumKitLoader::init() +{ + run(); + run_semaphore.wait(); // Wait for the thread to actually start. +} + +void DrumKitLoader::deinit() +{ if(running) { framesize_semaphore.post(); - stop(); - } - DEBUG(loader, "~DrumKitLoader() post\n"); + { + std::lock_guard guard(mutex); + load_queue.clear(); + } + + running = false; + semaphore.post(); + wait_stop(); + } } bool DrumKitLoader::loadkit(const std::string& file) @@ -140,18 +153,6 @@ void DrumKitLoader::loadKit(DrumKit *kit) semaphore.post(); // Start loader loop. } -void DrumKitLoader::stop() -{ - { - std::lock_guard guard(mutex); - load_queue.clear(); - } - - running = false; - semaphore.post(); - wait_stop(); -} - void DrumKitLoader::skip() { std::lock_guard guard(mutex); -- cgit v1.2.3