forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.h
34 lines (27 loc) · 942 Bytes
/
task.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef TASK_H
#define TASK_H
#include <QAtomicInt>
#include <QObject>
// Waits for a number of tasks to complete and emits allTasksDone() once all are
// complete.
class TaskWatcher : public QObject {
Q_OBJECT
public:
TaskWatcher(QObject* pParent=NULL);
virtual ~TaskWatcher();
// Increment the number of active tasks by one and watch pTask for
// doneSignal. This should be called before the task starts to prevent a
// race condition where the task completes before we listen for doneSignal.
void watchTask(QObject* pTask, const char* doneSignal);
signals:
// Signalled when all watched tasks are done from the thread that emitted
// the last taskDone() signal.
void allTasksDone();
private slots:
// Called when an individual task is done.
// WARNING: Invoked in the thread the task runs in.
void taskDone();
private:
QAtomicInt m_activeTasks;
};
#endif /* TASK_H */