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:
parent
43c82515fe
commit
d26e2957b0
7 changed files with 82 additions and 17 deletions
|
@ -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();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue