Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
workerthread.cpp
Go to the documentation of this file.
1 
2 #include <app/workerthread.h>
3 
4 using namespace frechet;
5 using namespace app;
6 
12 {
13  QMutexLocker guard(&mut);
14  if (job) job->cancelRequested=true;
15  job = new_job;
16  job->handle = this;
17  job->cancelRequested = false;
18  QThreadPool::globalInstance()->start(job);
19 }
20 
21 
23 {
24  QMutexLocker guard(&mut);
25  if (ajob==job) job = NULL;
26 }
34 {
35  QMutexLocker guard(&mut);
36  if (job) job->cancelRequested=true;
37 }
38 
40  cancelJob();
41  QThreadPool::globalInstance()->waitForDone();
42 }
43 
44 
46  try {
47  runJob();
48  } catch(InterruptedException&) {
50  } catch(...) {
51  std::cerr << "An Error occured" << std::endl;
52  }
53  handle->invalidate(this);
54  // Note: deletion is delegated to QThreadPool
55 }
virtual void afterInterrupted()=0
virtual void runJob()=0
abstract method for starting the job
WorkerJobHandle * handle
reference to thread-safe handle
Definition: workerthread.h:53
global definitions for all algorithms.
volatile bool cancelRequested
cancellation flag
Definition: workerthread.h:66
void invalidate(WorkerJob *ajob)
release control of the WorkerJob object
void cancelJob()
request the job to be cancelled
thrown by long-runner tasks
Definition: workerthread.h:27
virtual void run() override
abstract method that performs the long-running task
Background job to run long-runner tasks in a seperate thread.
Definition: workerthread.h:48
void shutDown()
cancel all remaining tasks and shut down the global QThreaPool
void startJob(WorkerJob *new_job)
start a new job
WorkerJob * job
the actual Worker Job object.
Definition: workerthread.h:91
QMutex mut
mutex protects read/write access.
Definition: workerthread.h:89