summaryrefslogtreecommitdiff
path: root/src/drumkitloader.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-05-22 16:44:11 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-05-22 16:44:11 +0200
commit624d25b8c3e9bd1648fdadbe28e1859cecab494f (patch)
treeac2331735a1e87e1fd5b49b3849542b0862b4453 /src/drumkitloader.cc
parent07415bae4e84a4c9316249f14c26c695c5dcadaa (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.cc37
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);