task: improve threading

This commit is contained in:
itsmattkc
2022-11-07 10:42:41 -08:00
parent a6cafe59a5
commit 373717629e
5 changed files with 11 additions and 5 deletions
+3
View File
@@ -93,6 +93,7 @@ public slots:
bool Start()
{
start_time_ = QDateTime::currentMSecsSinceEpoch();
emit Started(start_time_);
bool ret = Run();
@@ -150,6 +151,8 @@ protected:
}
signals:
void Started(qint64 start_time);
/**
* @brief Signal emitted whenever progress is made
*
+3 -2
View File
@@ -29,6 +29,7 @@ TaskManager* TaskManager::instance_ = nullptr;
TaskManager::TaskManager()
{
thread_pool_.setMaxThreadCount(1);
}
TaskManager::~TaskManager()
@@ -95,9 +96,9 @@ void TaskManager::AddTask(Task* t)
// Run task concurrently
watcher->setFuture(
#if QT_VERSION_MAJOR >= 6
QtConcurrent::run(&Task::Start, t)
QtConcurrent::run(&thread_pool_, &Task::Start, t)
#else
QtConcurrent::run(t, &Task::Start)
QtConcurrent::run(&thread_pool_, t, &Task::Start)
#endif
);
+2 -1
View File
@@ -22,6 +22,7 @@
#include <QDateTime>
#include <QHBoxLayout>
#include <cmath>
#include "common/timecodefunctions.h"
@@ -80,7 +81,7 @@ void ElapsedCounterWidget::UpdateTimers()
double ms_per_progress_unit = elapsed_ms / last_progress_;
double remaining_progress = 1.0 - last_progress_;
remaining_ms = qRound64(ms_per_progress_unit * remaining_progress);
remaining_ms = std::ceil(ms_per_progress_unit * remaining_progress);
} else {
elapsed_ms = 0;
remaining_ms = 0;
+2 -1
View File
@@ -37,8 +37,9 @@ public:
void SetProgress(double d);
void Start();
public slots:
void Start(qint64 start_time);
void Start();
public slots:
void Stop();
+1 -1
View File
@@ -72,9 +72,9 @@ TaskViewItem::TaskViewItem(Task* task, QWidget *parent) :
// Set up elapsed timer
status_stack_->setCurrentWidget(elapsed_timer_lbl_);
elapsed_timer_lbl_->Start(task_->GetStartTime());
// Connect to the task
connect(task_, &Task::Started, elapsed_timer_lbl_, qOverload<qint64>(&ElapsedCounterWidget::Start));
connect(task_, &Task::ProgressChanged, this, &TaskViewItem::UpdateProgress);
connect(cancel_btn_, &QPushButton::clicked, this, [this] { emit TaskCancelled(task_); });
}