Skip to content

Commit

Permalink
Fixed audio extractor job terminate
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Nov 30, 2024
1 parent e11ec27 commit 4ff5ebe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ui/misc/AudioExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void AudioExtractor::extractAsync(const void* ticket,
/** Exists */
if (it != this->templist.end()) {
if (auto ptrJob = dynamic_cast<AudioExtractorJob*>(it->second.job.get())) {
ptrJob->stopNow();
MainThreadPool::getInstance()->stopJob(ptrJob);
it->second.data = data;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/ui/misc/MainThreadPool.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MainThreadPool.h"

#define JOB_STOP_TIMEOUT 30000

MainThreadPool::MainThreadPool() {
this->pool = std::make_unique<juce::ThreadPool>();
}
Expand All @@ -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) {
Expand All @@ -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{});
Expand Down
1 change: 1 addition & 0 deletions src/ui/misc/MainThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MainThreadPool final : private juce::DeletedAtShutdown {
using Job = std::function<void(void)>;
void runJob(const Job& job);
void runJob(juce::ThreadPoolJob* job, bool deleteJobWhenFinished);
void stopJob(juce::ThreadPoolJob* job);

private:
std::unique_ptr<juce::ThreadPool> pool = nullptr;
Expand Down

0 comments on commit 4ff5ebe

Please sign in to comment.