Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
workerthread.h
Go to the documentation of this file.
1 #ifndef WORKERTHREAD_H
2 #define WORKERTHREAD_H
3 
4 #include <QRunnable>
5 #include <QMutex>
6 #include <QThreadPool>
7 
8 #include <iostream>
9 #include <freespace.h>
10 
11 namespace frechet { namespace app {
12 
13 class WorkerJobHandle;
14 
27 class InterruptedException : public std::exception {
28 
29 };
30 
48 class WorkerJob : public QRunnable
49 {
50 private:
51  friend class WorkerJobHandle;
54 public:
56 
66  volatile bool cancelRequested;
67 
69  virtual void runJob()=0;
72  virtual void afterInterrupted()=0;
73 
75  virtual void run() override;
76 };
77 
86 {
87 private:
89  QMutex mut;
92 public:
94  WorkerJobHandle() : mut(), job(NULL) { }
97  void startJob(WorkerJob* new_job);
99  void cancelJob();
102  void invalidate(WorkerJob* ajob);
104  void shutDown();
105 };
106 
107 
108 
109 } } // namespaces
110 
111 #endif // WORKERTHREAD_H
WorkerJobHandle()
default constructor with no job
Definition: workerthread.h:94
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
Thread safe access to a WorkerJob.
Definition: workerthread.h:85
WorkerJob * job
the actual Worker Job object.
Definition: workerthread.h:91
QMutex mut
mutex protects read/write access.
Definition: workerthread.h:89