GpgFrontend Project A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.

TaskRunner.h
1
27 #ifndef GPGFRONTEND_TASKRUNNER_H
28 #define GPGFRONTEND_TASKRUNNER_H
29
30 #include <cstddef>
31 #include <mutex>
32 #include <queue>
33
34 #include "core/GpgFrontendCore.h"
35
36 namespace GpgFrontend::Thread {
37
38 class Task;
39
40 class GPGFRONTEND_CORE_EXPORT TaskRunner : public QThread {
41 Q_OBJECT
42 public:
47 TaskRunner();
48
53 virtual ~TaskRunner() override;
54
59 [[noreturn]] void run() override;
60
61 public slots:
62
68 void PostTask(Task* task);
69
76 void PostScheduleTask(Task* task, size_t seconds);
77
78 private:
79 std::queue<Task*> tasks;
80 std::map<std::string, Task*> pending_tasks_;
81 std::mutex tasks_mutex_;
82 QThreadPool thread_pool_{this};
83
88 void unregister_finished_task(std::string);
89 };
90 } // namespace GpgFrontend::Thread
91
92 #endif // GPGFRONTEND_TASKRUNNER_H
GpgFrontend::Thread::TaskRunner
Definition: TaskRunner.h:40
GpgFrontend::Thread::TaskRunner::tasks_mutex_
std::mutex tasks_mutex_
The task queue mutex.
Definition: TaskRunner.h:81
GpgFrontend::Thread::TaskRunner::pending_tasks_
std::map< std::string, Task * > pending_tasks_
The pending tasks.
Definition: TaskRunner.h:80
GpgFrontend::Thread::TaskRunner::tasks
std::queue< Task * > tasks
The task queue.
Definition: TaskRunner.h:79
GpgFrontend::Thread::TaskRunner::~TaskRunner
virtual ~TaskRunner() override
Destroy the Task Runner object.
GpgFrontend::Thread::TaskRunner::TaskRunner
TaskRunner()
Construct a new Task Runner object.
GpgFrontend::Thread::Task
Definition: Task.h:45
GpgFrontend::Thread
Definition: CtxCheckTask.h:33