Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
AttachmentQueueManager Class Referencefinal

Manages a queue of AttachmentTasks for concurrent execution using a singleton pattern. More...

#include <attachment_queue_manager.h>

Inheritance diagram for AttachmentQueueManager:
Collaboration diagram for AttachmentQueueManager:

Public Member Functions

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.
 

Static Public Member Functions

static AttachmentQueueManagerGetInstance ()
 Gets the singleton instance of the AttachmentQueueManager.
 

Private Member Functions

 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.
 

Private Attributes

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_.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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
parentOptional parent QObject.
Here is the caller graph for this function:

Member Function Documentation

◆ 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
TaskFuncThe function to be executed as a task.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetInstance()

static AttachmentQueueManager * AttachmentQueueManager::GetInstance ( )
inlinestatic

Gets the singleton instance of the AttachmentQueueManager.

Returns
Pointer to the singleton AttachmentQueueManager instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the caller graph for this function:

Member Data Documentation

◆ active_tasks_

QList<AttachmentTask *> AttachmentQueueManager::active_tasks_
private

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_

QQueue<AttachmentTask *> AttachmentQueueManager::task_queue_
private

Queue storing tasks waiting to be executed. Access protected by mutex_.


The documentation for this class was generated from the following files: