Files
EJM_Display/Threads/MultiCoreManager.h

105 lines
2.1 KiB
C
Raw Normal View History

2025-10-20 22:28:37 +08:00
#ifndef MULTICOREMANAGER_H
#define MULTICOREMANAGER_H
#include <QObject>
#include <QThreadPool>
#include <QMap>
#include <QMutex>
#include <functional>
#include <QString>
/**
* @brief The MultiCoreManager class
*
*/
class MultiCoreManager : public QObject
{
Q_OBJECT
private:
static MultiCoreManager* m_instance;
static QMutex m_mutex;
explicit MultiCoreManager(QObject *parent = nullptr);
// 线程池
QThreadPool* m_threadPool;
// 任务统计
QMap<QString, int> m_taskCount;
mutable QMutex m_taskCountMutex;
// CPU核心数
int m_cpuCount;
public:
/**
* @brief
*/
static MultiCoreManager* instance(QObject *parent = nullptr);
/**
* @brief
*/
~MultiCoreManager();
/**
* @brief 线
* @param task
* @param taskType
*/
void submitTask(std::function<void()> task, const QString& taskType = "general");
/**
* @brief 线
*/
int activeThreadCount() const;
/**
* @brief 线
*/
int maxThreadCount() const;
/**
* @brief 线
*/
void setMaxThreadCount(int count);
/**
* @brief
*/
QMap<QString, int> taskStatistics() const;
/**
* @brief
* @param msecs
*/
void waitForDone(int msecs = -1);
public slots:
/**
* @brief 线
*/
void clearThreadPool();
/**
* @brief 线
*/
void printStatus() const;
signals:
/**
* @brief
* @param taskType
*/
void taskCompleted(const QString& taskType);
/**
* @brief
* @param activeThreads 线
* @param maxThreads 线
*/
void statusUpdated(int activeThreads, int maxThreads);
};
#endif // MULTICOREMANAGER_H