added cross-platform

This commit is contained in:
2023-12-03 15:31:50 +03:00
parent c4b8e2dd7a
commit 0afbb32788
7 changed files with 103 additions and 42 deletions

View File

@@ -1,6 +1,8 @@
#pragma once
#include <unistd.h>
#include <map>
#include <vector>
#include <queue>
#include "File.h"
#include "Task.h"
@@ -56,6 +58,28 @@ public:
delete packedTasks;
delete lines;
}
void changeState() {
switch (this->state) {
case WorkspacesCreation:
this->state = Preparation;
saveState();
break;
case Preparation:
this->state = Execution;
saveState();
break;
case Execution:
Finalize();
this->state = End;
saveState();
break;
default:
this->state = End;
break;
}
}
void Do() {
saveState();
long activeCount = 0;
@@ -99,34 +123,38 @@ public:
}
}
// printf("active count = %d\n", activeCount);
if (activeCount == 0) {
switch (this->state) {
case WorkspacesCreation:
this->state = Preparation;
saveState();
break;
case Preparation:
this->state = Execution;
saveState();
break;
case Execution:
Finalize();
this->state = End;
saveState();
break;
default:
this->state = End;
break;
}
}
if (activeCount == 0)
changeState();
Utils::Sleep(2);
}
}
void DoWithSchedule(int maxKernels) {
saveState();
map<int, queue<T*>> sortedByKernelNeeds;
long activeTasks = 0;
for (auto& task : this->getElements()) {
if (task->getState() == WorkspaceReady) {
activeTasks++;
sortedByKernelNeeds[task->getKernels()].push(task);
}
}
printf("total tasks count = %ld, active task count %ld\n", this->getLength(), activeTasks);
while (activeTasks) {
}
changeState();
}
virtual void Finalize() {}
void saveState() {
Utils::Sleep(1); //чтобы не было одинаковых по дате файлов.
String stateFile = packageWorkspace + "/state/" + getStatePrefix() + printState();
//printf("stateFile=<%s>\n", stateFile.getCharArray());
File(stateFile, Utils::getDate());
File tmp(stateFile, Utils::getDate());
}
};