1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Fixed ability to cancel downloads

This commit is contained in:
Brian Fiete 2019-09-04 10:27:37 -07:00
parent 43c82515fe
commit d26e2957b0
7 changed files with 82 additions and 17 deletions

View file

@ -8,6 +8,7 @@ static BF_TLS_DECLSPEC ThreadPool* gPoolParent;
ThreadPool::Thread::Thread()
{
mCurJobThreadId = -1;
mActiveJob = NULL;
}
ThreadPool::Thread::~Thread()
@ -34,9 +35,10 @@ void ThreadPool::Thread::Proc()
{
job = mThreadPool->mJobs[0];
job->mProcessing = true;
mThreadPool->mJobs.RemoveAt(0);
mThreadPool->mJobs.RemoveAt(0);
}
mActiveJob = job;
if (job == NULL)
mCurJobThreadId = -1;
else
@ -76,6 +78,7 @@ void ThreadPool::Thread::Proc()
// Run dtor synchronized
AutoCrit autoCrit(mThreadPool->mCritSect);
mActiveJob = NULL;
delete job;
}
}
@ -176,4 +179,14 @@ void ThreadPool::AddJob(BfpThreadStartProc proc, void* param, int maxWorkersPerP
bool ThreadPool::IsInJob()
{
return gPoolParent == this;
}
void ThreadPool::CancelAll()
{
AutoCrit autoCrit(mCritSect);
for (auto job : mJobs)
job->Cancel();
for (auto thread : mThreads)
if (thread->mActiveJob != NULL)
thread->mActiveJob->Cancel();
}