task manager will trigger new tasks as old tasks end
This commit is contained in:
+5
-1
@@ -155,7 +155,11 @@ void Core::ImportFiles(const QStringList &urls)
|
|||||||
f->set_timestamp(file_info.lastModified());
|
f->set_timestamp(file_info.lastModified());
|
||||||
|
|
||||||
//olive::ProbeMedia(f);
|
//olive::ProbeMedia(f);
|
||||||
olive::task_manager.AddTask(new Task());
|
// FIXME: Test code only
|
||||||
|
for (int i=0;i<8;i++) {
|
||||||
|
olive::task_manager.AddTask(new Task());
|
||||||
|
}
|
||||||
|
// End test code
|
||||||
|
|
||||||
active_project->root()->add_child(f);
|
active_project->root()->add_child(f);
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,30 @@ void TaskManager::AddTask(Task* t)
|
|||||||
|
|
||||||
tasks_.append(t);
|
tasks_.append(t);
|
||||||
|
|
||||||
if (tasks_.size() < maximum_task_count_) {
|
StartNextWaiting();
|
||||||
t->Start();
|
}
|
||||||
|
|
||||||
|
void TaskManager::StartNextWaiting()
|
||||||
|
{
|
||||||
|
// Count the tasks that are currently active
|
||||||
|
int working_count = 0;
|
||||||
|
|
||||||
|
for (int i=0;i<tasks_.size();i++) {
|
||||||
|
Task* t = tasks_.at(i);
|
||||||
|
|
||||||
|
if (t->status() == Task::kWorking) {
|
||||||
|
// Task is active, add it to the count
|
||||||
|
working_count++;
|
||||||
|
} else if (t->status() == Task::kWaiting) {
|
||||||
|
// Task is waiting and we have available threads, start it and add it to the count
|
||||||
|
t->Start();
|
||||||
|
working_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the count exceeds our maximum threads, if so stop here
|
||||||
|
if (working_count == maximum_task_count_) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,9 +74,11 @@ void TaskManager::TaskCallback(Task::Status status)
|
|||||||
break;
|
break;
|
||||||
case Task::kFinished:
|
case Task::kFinished:
|
||||||
qDebug() << sender() << "finished successfully.";
|
qDebug() << sender() << "finished successfully.";
|
||||||
|
StartNextWaiting();
|
||||||
break;
|
break;
|
||||||
case Task::kError:
|
case Task::kError:
|
||||||
qDebug() << sender() << "failed:" << static_cast<Task*>(sender())->error();
|
qDebug() << sender() << "failed:" << static_cast<Task*>(sender())->error();
|
||||||
|
StartNextWaiting();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ public:
|
|||||||
void AddTask(Task *t);
|
void AddTask(Task *t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void StartNextWaiting();
|
||||||
|
|
||||||
QVector<Task*> tasks_;
|
QVector<Task*> tasks_;
|
||||||
|
|
||||||
int maximum_task_count_;
|
int maximum_task_count_;
|
||||||
|
|||||||
Reference in New Issue
Block a user