Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
attachment_queue_manager.h
Go to the documentation of this file.
1#ifndef ATTACHMENT_QUEUE_MANAGER_H
2#define ATTACHMENT_QUEUE_MANAGER_H
3
4#include <QMutex>
5#include <QObject>
6#include <QQueue>
7#include <QRunnable>
8
15class AttachmentTask final : public QObject, public QRunnable {
16 Q_OBJECT
17
18public:
24 explicit AttachmentTask(const std::function<void()> &taskFunc, QObject *parent = nullptr);
25
30 void run() override;
31
32signals:
36 void finished();
37
38private:
40 std::function<void()> TaskFunc_;
41};
42
50class AttachmentQueueManager final : public QObject {
51 Q_OBJECT
52
53public:
59 static AttachmentQueueManager instance;
60 return &instance;
61 }
62
69 void AddTask(const std::function<void()> &TaskFunc);
70
71private:
77 explicit AttachmentQueueManager(QObject *parent = nullptr);
78
85 void ProcessQueue();
86
88 QQueue<AttachmentTask *> task_queue_;
90 QList<AttachmentTask *> active_tasks_;
92 QMutex mutex_;
95};
96
97#endif // ATTACHMENT_QUEUE_MANAGER_H
QList< AttachmentTask * > active_tasks_
List storing tasks currently being executed by the thread pool. Access protected by mutex_.
Definition attachment_queue_manager.h:90
QMutex mutex_
Mutex ensuring thread-safe access to task_queue_ and active_tasks_.
Definition attachment_queue_manager.h:92
int max_active_tasks_
Maximum number of tasks allowed to run concurrently.
Definition attachment_queue_manager.h:94
AttachmentQueueManager(QObject *parent=nullptr)
Private constructor to enforce the singleton pattern. Determines the maximum number of concurrent tas...
Definition attachment_queue_manager.cpp:30
void AddTask(const std::function< void()> &TaskFunc)
Adds a new task (represented by a std::function) to the execution queue. Creates an AttachmentTask wr...
Definition attachment_queue_manager.cpp:15
void ProcessQueue()
Processes the task queue, starting new tasks if slots are available. Checks if the number of active t...
Definition attachment_queue_manager.cpp:34
static AttachmentQueueManager * GetInstance()
Gets the singleton instance of the AttachmentQueueManager.
Definition attachment_queue_manager.h:58
QQueue< AttachmentTask * > task_queue_
Queue storing tasks waiting to be executed. Access protected by mutex_.
Definition attachment_queue_manager.h:88
void finished()
Emitted after the task function (TaskFunc_) has finished executing.
std::function< void()> TaskFunc_
The function object that represents the task to be executed.
Definition attachment_queue_manager.h:40
AttachmentTask(const std::function< void()> &taskFunc, QObject *parent=nullptr)
Constructs an AttachmentTask.
Definition attachment_queue_manager.cpp:5
void run() override
Executes the stored task function (TaskFunc_). Called by the QThreadPool when the task is started....
Definition attachment_queue_manager.cpp:10