-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.h
More file actions
executable file
·43 lines (33 loc) · 775 Bytes
/
worker.h
File metadata and controls
executable file
·43 lines (33 loc) · 775 Bytes
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
35
36
37
38
39
40
41
42
43
#ifndef WORKER_H
#define WORKER_H
#include <condition_variable>
#include <QThread>
#include "iTask.h"
class Worker : public QThread
{
Q_OBJECT
public:
explicit Worker(QObject *parent = nullptr);
void assignTask(ITask* task);
bool isRun() const;
std::string getStatus() const;
int getId() const;
int getTaskId() const;
void stop();
void stopTask();
signals:
void taskFinished(int workerId);
void changeStatus(int workerId);
protected:
void run() override;
int taskId = 0;
private:
ITask* task = nullptr;
int workerId;
std::atomic<bool> running;
std::string status;
static std::atomic<int> countWorkers;
std::mutex taskMutex;
std::condition_variable taskCondition;
};
#endif // WORKER_H