Manages a queue of AttachmentTasks for concurrent execution using a singleton pattern.
More...
#include <attachment_queue_manager.h>
|
| void | AddTask (const std::function< void()> &TaskFunc) |
| | Adds a new task (represented by a std::function) to the execution queue. Creates an AttachmentTask wrapper for the function, adds it to the queue, and attempts to process the queue immediately. This operation is thread-safe.
|
| |
|
| | AttachmentQueueManager (QObject *parent=nullptr) |
| | Private constructor to enforce the singleton pattern. Determines the maximum number of concurrent tasks based on available system threads.
|
| |
| void | ProcessQueue () |
| | Processes the task queue, starting new tasks if slots are available. Checks if the number of active tasks is below the maximum limit and if the queue is not empty. If conditions are met, dequeues a task and starts it using the global QThreadPool. This operation is protected by the internal mutex.
|
| |
|
| QList< AttachmentTask * > | active_tasks_ |
| | List storing tasks currently being executed by the thread pool. Access protected by mutex_.
|
| |
| int | max_active_tasks_ |
| | Maximum number of tasks allowed to run concurrently.
|
| |
| QMutex | mutex_ |
| | Mutex ensuring thread-safe access to task_queue_ and active_tasks_.
|
| |
| QQueue< AttachmentTask * > | task_queue_ |
| | Queue storing tasks waiting to be executed. Access protected by mutex_.
|
| |
Manages a queue of AttachmentTasks for concurrent execution using a singleton pattern.
This class limits the number of concurrently running tasks (typically related to loading or processing attachments) to avoid overwhelming system resources. It uses QThreadPool to manage the execution of tasks.
◆ AttachmentQueueManager()
| AttachmentQueueManager::AttachmentQueueManager |
( |
QObject * | parent = nullptr | ) |
|
|
explicitprivate |
Private constructor to enforce the singleton pattern. Determines the maximum number of concurrent tasks based on available system threads.
- Parameters
-
| parent | Optional parent QObject. |
◆ AddTask()
| void AttachmentQueueManager::AddTask |
( |
const std::function< void()> & | TaskFunc | ) |
|
Adds a new task (represented by a std::function) to the execution queue. Creates an AttachmentTask wrapper for the function, adds it to the queue, and attempts to process the queue immediately. This operation is thread-safe.
- Parameters
-
| TaskFunc | The function to be executed as a task. |
◆ GetInstance()
◆ ProcessQueue()
| void AttachmentQueueManager::ProcessQueue |
( |
| ) |
|
|
private |
Processes the task queue, starting new tasks if slots are available. Checks if the number of active tasks is below the maximum limit and if the queue is not empty. If conditions are met, dequeues a task and starts it using the global QThreadPool. This operation is protected by the internal mutex.
◆ active_tasks_
List storing tasks currently being executed by the thread pool. Access protected by mutex_.
◆ max_active_tasks_
| int AttachmentQueueManager::max_active_tasks_ |
|
private |
Maximum number of tasks allowed to run concurrently.
◆ mutex_
| QMutex AttachmentQueueManager::mutex_ |
|
private |
Mutex ensuring thread-safe access to task_queue_ and active_tasks_.
◆ task_queue_
Queue storing tasks waiting to be executed. Access protected by mutex_.
The documentation for this class was generated from the following files: