diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-05-22 16:44:11 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-05-22 16:44:11 +0200 |
commit | 624d25b8c3e9bd1648fdadbe28e1859cecab494f (patch) | |
tree | ac2331735a1e87e1fd5b49b3849542b0862b4453 /src/drumkitloader.cc | |
parent | 07415bae4e84a4c9316249f14c26c695c5dcadaa (diff) |
Explicitly stop the loader thread to ensure we don't delete the DrumGizmo::drumkit member while the loader is attached to it.
Diffstat (limited to 'src/drumkitloader.cc')
-rw-r--r-- | src/drumkitloader.cc | 37 |
1 files changed, 19 insertions, 18 deletions
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<std::mutex> 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<std::mutex> guard(mutex); - load_queue.clear(); - } - - running = false; - semaphore.post(); - wait_stop(); -} - void DrumKitLoader::skip() { std::lock_guard<std::mutex> guard(mutex); |