diff --git a/src/ui/misc/AudioExtractor.cpp b/src/ui/misc/AudioExtractor.cpp index b53b4eb..87938de 100644 --- a/src/ui/misc/AudioExtractor.cpp +++ b/src/ui/misc/AudioExtractor.cpp @@ -157,7 +157,7 @@ void AudioExtractor::extractAsync(const void* ticket, /** Exists */ if (it != this->templist.end()) { if (auto ptrJob = dynamic_cast(it->second.job.get())) { - ptrJob->stopNow(); + MainThreadPool::getInstance()->stopJob(ptrJob); it->second.data = data; } } diff --git a/src/ui/misc/MainThreadPool.cpp b/src/ui/misc/MainThreadPool.cpp index ceb80f1..9baac6a 100644 --- a/src/ui/misc/MainThreadPool.cpp +++ b/src/ui/misc/MainThreadPool.cpp @@ -1,5 +1,7 @@ #include "MainThreadPool.h" +#define JOB_STOP_TIMEOUT 30000 + MainThreadPool::MainThreadPool() { this->pool = std::make_unique(); } @@ -9,7 +11,7 @@ MainThreadPool::~MainThreadPool() { } void MainThreadPool::stopAll() { - this->pool->removeAllJobs(true, 30000, nullptr); + this->pool->removeAllJobs(true, JOB_STOP_TIMEOUT, nullptr); } void MainThreadPool::runJob(const Job& job) { @@ -21,6 +23,10 @@ void MainThreadPool::runJob( this->pool->addJob(job, deleteJobWhenFinished); } +void MainThreadPool::stopJob(juce::ThreadPoolJob* job) { + this->pool->removeJob(job, true, JOB_STOP_TIMEOUT); +} + MainThreadPool* MainThreadPool::getInstance() { return MainThreadPool::instance ? MainThreadPool::instance : (MainThreadPool::instance = new MainThreadPool{}); diff --git a/src/ui/misc/MainThreadPool.h b/src/ui/misc/MainThreadPool.h index e96a6c5..67f3552 100644 --- a/src/ui/misc/MainThreadPool.h +++ b/src/ui/misc/MainThreadPool.h @@ -11,6 +11,7 @@ class MainThreadPool final : private juce::DeletedAtShutdown { using Job = std::function; void runJob(const Job& job); void runJob(juce::ThreadPoolJob* job, bool deleteJobWhenFinished); + void stopJob(juce::ThreadPoolJob* job); private: std::unique_ptr pool = nullptr;