added cross-platform
This commit is contained in:
@@ -24,7 +24,7 @@ public:
|
||||
}
|
||||
|
||||
long getLength() const {
|
||||
return elements.size();
|
||||
return (long)elements.size();
|
||||
}
|
||||
|
||||
T* get(long i) {
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
using namespace std;
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#include <filesystem>
|
||||
#endif
|
||||
|
||||
#include "CompilationSupervisor.h"
|
||||
#include "RunSupervisor.h"
|
||||
#include "Global.h"
|
||||
@@ -11,7 +18,13 @@ int main(int argc, char ** argv)
|
||||
freeKernels = maxKernels;
|
||||
busyKernels= 0;
|
||||
//--
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
std::filesystem::current_path(packageWorkspace.getCharArray());
|
||||
#else
|
||||
chdir(packageWorkspace.getCharArray());
|
||||
#endif
|
||||
|
||||
userWorkspace.println();
|
||||
packageWorkspace.println();
|
||||
printf("%d\n", maxKernels);
|
||||
|
||||
@@ -17,14 +17,14 @@ public:
|
||||
}
|
||||
|
||||
String(const char* s) {
|
||||
length = strlen(s);
|
||||
length = (long)strlen(s);
|
||||
body = new char[length + 1];
|
||||
for (long i = 0; i < length; ++i)
|
||||
body[i] = s[i];
|
||||
body[length] = '\0';
|
||||
}
|
||||
String(const char* s, char ps) {
|
||||
length = strlen(s);
|
||||
length = (long)strlen(s);
|
||||
body = new char[length + 1];
|
||||
for (long i = 0; i < length; ++i) {
|
||||
body[i] = (s[i] == ps) ? '\n' : s[i];
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
};
|
||||
@@ -123,9 +123,12 @@ public:
|
||||
File launchScriptFile = File(launchScriptPath, launchScriptText);
|
||||
Utils::Chmod(launchScriptPath);
|
||||
}
|
||||
virtual void Start() {
|
||||
|
||||
if (kernels <= freeKernels) {
|
||||
int getKernels() const { return kernels; }
|
||||
|
||||
virtual void Start(bool dontCheck = false) {
|
||||
|
||||
if (kernels <= freeKernels || dontCheck) {
|
||||
system(getStartCommand().getCharArray());
|
||||
state = Running;
|
||||
//-
|
||||
@@ -134,13 +137,10 @@ public:
|
||||
//-
|
||||
}
|
||||
}
|
||||
virtual void analyseResults() {
|
||||
state = Finished;
|
||||
}
|
||||
|
||||
virtual void Check() {
|
||||
if (Utils::Exists(workspace + "/DONE")) {
|
||||
if (Utils::Exists(workspace + "/DONE"))
|
||||
analyseResults();
|
||||
}
|
||||
else {
|
||||
if (Utils::Exists(workspace + "/TIMEOUT")) {
|
||||
state = AbortedByTimeout;
|
||||
@@ -150,6 +150,7 @@ public:
|
||||
state = AbortedByUser;
|
||||
}
|
||||
}
|
||||
|
||||
if (state != Running) {
|
||||
//-
|
||||
busyKernels = Utils::min(busyKernels - kernels, maxKernels);
|
||||
@@ -158,8 +159,13 @@ public:
|
||||
saveState(); //не нужно. только для отладки. анализ будет делаться архивом.
|
||||
}
|
||||
}
|
||||
|
||||
virtual void analyseResults() {
|
||||
state = Finished;
|
||||
}
|
||||
|
||||
virtual void saveState() {
|
||||
String stateFile = workspace + "/TaskState";
|
||||
File(stateFile, printState());
|
||||
File tmp(stateFile, printState());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ public:
|
||||
printf("text length=%ld\n", this->getLength());
|
||||
|
||||
auto elems = this->getElements();
|
||||
for (size_t i = 0; i < elems.size(); ++i) {
|
||||
for (long i = 0; i < elems.size(); ++i) {
|
||||
printf("i=%ld; [%s]\n", i, elems[i]->getCharArray());
|
||||
// elements[i]->println();
|
||||
}
|
||||
|
||||
@@ -3,8 +3,14 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#include <filesystem>
|
||||
#endif
|
||||
|
||||
#include "String.h"
|
||||
|
||||
class Utils {
|
||||
@@ -16,31 +22,39 @@ public:
|
||||
return (a > b) ? b : a;
|
||||
}
|
||||
static void Mkdir(const String& path) {
|
||||
#if __cplusplus >= 201703L
|
||||
std::filesystem::create_directory(path.getCharArray());
|
||||
#else
|
||||
mkdir(path.getCharArray(), 0777);
|
||||
#endif
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/4568681/using-chmod-in-a-c-program
|
||||
static void Chmod(const String& path) {
|
||||
String command = "chmod 777 " + String::DQuotes(path);
|
||||
system(command.getCharArray());
|
||||
}
|
||||
|
||||
//https://stackoverflow.com/questions/230062/whats-the-best-way-to-check-if-a-file-exists-in-c
|
||||
static bool Exists(const String& path) {
|
||||
struct stat buffer;
|
||||
return (stat(path.getCharArray(), &buffer) == 0);
|
||||
}
|
||||
|
||||
//in seconds
|
||||
static void Sleep(int s) {
|
||||
usleep(s * 1000000);
|
||||
std::chrono::seconds timespan(s);
|
||||
std::this_thread::sleep_for(timespan);
|
||||
}
|
||||
static void Copy(const String& src, const String& dst) {
|
||||
String command = "cp " + String::DQuotes(src) + " " + String::DQuotes(dst);
|
||||
system(command.getCharArray());
|
||||
}
|
||||
static long getAbsoluteTime() {
|
||||
static time_t getAbsoluteTime() {
|
||||
return time(NULL);
|
||||
}
|
||||
static String getDate() {
|
||||
long int ttime;
|
||||
ttime = time(NULL);
|
||||
auto ttime = time(NULL);
|
||||
String res(ctime(&ttime));
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user