Added id to InsightWorker objects

This commit is contained in:
Nav
2022-09-08 15:29:54 +01:00
parent 7a8efcd7fc
commit 77cd13bf46
3 changed files with 12 additions and 5 deletions

View File

@@ -181,7 +181,7 @@ namespace Bloom
// Prepare worker thread // Prepare worker thread
this->workerThread = new QThread(); this->workerThread = new QThread();
this->workerThread->setObjectName("IW"); this->workerThread->setObjectName("IW" + QString::number(this->insightWorker->id));
this->insightWorker->moveToThread(this->workerThread); this->insightWorker->moveToThread(this->workerThread);
QObject::connect(this->workerThread, &QThread::started, this->insightWorker, &InsightWorker::startup); QObject::connect(this->workerThread, &QThread::started, this->insightWorker, &InsightWorker::startup);
QObject::connect(this->workerThread, &QThread::finished, this->insightWorker, &QObject::deleteLater); QObject::connect(this->workerThread, &QThread::finished, this->insightWorker, &QObject::deleteLater);

View File

@@ -12,7 +12,7 @@ namespace Bloom
using Bloom::Targets::TargetState; using Bloom::Targets::TargetState;
void InsightWorker::startup() { void InsightWorker::startup() {
Logger::debug("Starting InsightWorker thread"); Logger::debug("Starting InsightWorker" + std::to_string(this->id) + " thread");
QObject::connect( QObject::connect(
InsightSignals::instance(), InsightSignals::instance(),
@@ -21,6 +21,7 @@ namespace Bloom
&InsightWorker::executeTasks &InsightWorker::executeTasks
); );
Logger::debug("InsightWorker" + std::to_string(this->id) + " thread ready");
emit this->ready(); emit this->ready();
} }

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include <cstdint>
#include <atomic>
#include <QtCore> #include <QtCore>
#include <queue> #include <queue>
@@ -10,6 +12,8 @@
namespace Bloom namespace Bloom
{ {
static_assert(std::atomic<std::uint8_t>::is_always_lock_free);
/** /**
* The InsightWorker runs on a separate thread to the main GUI thread. Its purpose is to handle any * The InsightWorker runs on a separate thread to the main GUI thread. Its purpose is to handle any
* blocking/time-expensive operations. * blocking/time-expensive operations.
@@ -19,8 +23,9 @@ namespace Bloom
Q_OBJECT Q_OBJECT
public: public:
InsightWorker() = default; const std::uint8_t id = ++(InsightWorker::lastWorkerId);
InsightWorker() = default;
void startup(); void startup();
static void queueTask(InsightWorkerTask* task); static void queueTask(InsightWorkerTask* task);
@@ -28,10 +33,11 @@ namespace Bloom
void ready(); void ready();
private: private:
TargetController::TargetControllerConsole targetControllerConsole = TargetController::TargetControllerConsole(); static inline std::atomic<std::uint8_t> lastWorkerId = 0;
static inline SyncSafe<std::queue<InsightWorkerTask*>> queuedTasks = {}; static inline SyncSafe<std::queue<InsightWorkerTask*>> queuedTasks = {};
TargetController::TargetControllerConsole targetControllerConsole = TargetController::TargetControllerConsole();
static std::optional<InsightWorkerTask*> getQueuedTask(); static std::optional<InsightWorkerTask*> getQueuedTask();
void executeTasks(); void executeTasks();
}; };