threaded exception handling
Some checks failed
demo.yaml / threaded exception handling (push) Failing after 0s
Some checks failed
demo.yaml / threaded exception handling (push) Failing after 0s
This commit is contained in:
parent
598c666e91
commit
c2bb9023d4
14 changed files with 237 additions and 127 deletions
|
|
@ -24,7 +24,7 @@ import :Command;
|
|||
namespace fs = std::filesystem;
|
||||
|
||||
namespace Crafter {
|
||||
ModulePartition::ModulePartition(std::string&& name, fs::path&& path) : name(std::move(name)), path(std::move(path)), compiled(false), checked(false) {}
|
||||
ModulePartition::ModulePartition(std::string&& name, fs::path&& path) : name(std::move(name)), path(std::move(path)), compiled(CRAFTER_COMPILE_STATUS_WAITING), checked(false) {}
|
||||
|
||||
bool ModulePartition::Check(const fs::path& pcmDir) {
|
||||
if(!checked) {
|
||||
|
|
@ -43,7 +43,7 @@ namespace Crafter {
|
|||
}
|
||||
}
|
||||
needsRecompiling = false;
|
||||
compiled.store(true);
|
||||
compiled.store(CRAFTER_COMPILE_STATUS_COMPLETED);
|
||||
return false;
|
||||
} else {
|
||||
needsRecompiling = true;
|
||||
|
|
@ -54,24 +54,34 @@ namespace Crafter {
|
|||
}
|
||||
}
|
||||
|
||||
void ModulePartition::Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir) {
|
||||
void ModulePartition::Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result) {
|
||||
for(ModulePartition* dependency : partitionDependencies) {
|
||||
if(!dependency->compiled.load()) {
|
||||
//std::cout << std::format("{} is waiting on {} {}", name, dependency->name, dependency->needsRecompiling) << std::endl;
|
||||
dependency->compiled.wait(false);
|
||||
dependency->compiled.wait(CRAFTER_COMPILE_STATUS_WAITING);
|
||||
if(dependency->compiled.load() == CRAFTER_COMPILE_STATUS_ERROR) {
|
||||
compiled.store(CRAFTER_COMPILE_STATUS_ERROR);
|
||||
compiled.notify_all();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
||||
RunClang(std::format("{} {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
||||
compiled.store(true);
|
||||
compiled.notify_all();
|
||||
result += RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
||||
result += RunClang(std::format("{} {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
||||
if(result.empty()) {
|
||||
compiled.store(CRAFTER_COMPILE_STATUS_COMPLETED);
|
||||
compiled.notify_all();
|
||||
} else {
|
||||
compiled.store(CRAFTER_COMPILE_STATUS_ERROR);
|
||||
compiled.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
Module::Module(std::string&& name, fs::path&& path, std::vector<std::unique_ptr<ModulePartition>>&& partitions) : name(std::move(name)), path(std::move(path)), partitions(std::move(partitions)), compiled(false), checked(false) {}
|
||||
Module::Module(std::string&& name, fs::path&& path, std::vector<std::unique_ptr<ModulePartition>>&& partitions) : name(std::move(name)), path(std::move(path)), partitions(std::move(partitions)), compiled(CRAFTER_COMPILE_STATUS_WAITING), checked(false) {}
|
||||
|
||||
Module::Module(std::string&& name, fs::path&& path) : name(std::move(name)), path(std::move(path)), compiled(false), checked(false) {}
|
||||
Module::Module(std::string&& name, fs::path&& path) : name(std::move(name)), path(std::move(path)), compiled(CRAFTER_COMPILE_STATUS_WAITING), checked(false) {}
|
||||
|
||||
Module::Module(fs::path&& path) : path(std::move(path)), compiled(false), checked(false) {
|
||||
Module::Module(fs::path&& path) : path(std::move(path)), compiled(CRAFTER_COMPILE_STATUS_WAITING), checked(false) {
|
||||
std::ifstream t(this->path);
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
|
|
@ -101,7 +111,7 @@ namespace Crafter {
|
|||
return true;
|
||||
} else {
|
||||
needsRecompiling = false;
|
||||
compiled.store(true);
|
||||
compiled.store(CRAFTER_COMPILE_STATUS_COMPLETED);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -115,14 +125,13 @@ namespace Crafter {
|
|||
return needsRecompiling;
|
||||
}
|
||||
}
|
||||
|
||||
void Module::Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir) {
|
||||
|
||||
void Module::Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::string& result) {
|
||||
std::vector<std::thread> threads;
|
||||
for(std::unique_ptr<ModulePartition>& partition : partitions) {
|
||||
if(partition->needsRecompiling) {
|
||||
threads.emplace_back([&partition, clang, &pcmDir, &buildDir](){
|
||||
partition->Compile(clang, pcmDir, buildDir);
|
||||
});
|
||||
std::vector<std::string> results(partitions.size());
|
||||
for(std::uint_fast32_t i = 0; i < partitions.size(); i++) {
|
||||
if( partitions[i]->needsRecompiling) {
|
||||
threads.emplace_back(&ModulePartition::Compile, partitions[i].get(), clang, pcmDir, buildDir, std::ref(results[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -130,10 +139,23 @@ namespace Crafter {
|
|||
thread.join();
|
||||
}
|
||||
|
||||
RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
||||
RunClang(std::format("{} {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
||||
for(const std::string& result2 : results) {
|
||||
result += result2;
|
||||
}
|
||||
|
||||
compiled.store(true);
|
||||
compiled.notify_all();
|
||||
if(result.empty()) {
|
||||
result += RunClang(std::format("{} {}.cppm --precompile -o {}.pcm", clang, path.string(), (pcmDir/path.filename()).string()));
|
||||
result += RunClang(std::format("{} {}.pcm -c -o {}.o", clang, (pcmDir/path.filename()).string(), (buildDir/path.filename()).string()));
|
||||
if(result.empty()) {
|
||||
compiled.store(CRAFTER_COMPILE_STATUS_COMPLETED);
|
||||
compiled.notify_all();
|
||||
} else {
|
||||
compiled.store(CRAFTER_COMPILE_STATUS_ERROR);
|
||||
compiled.notify_all();
|
||||
}
|
||||
} else {
|
||||
compiled.store(CRAFTER_COMPILE_STATUS_ERROR);
|
||||
compiled.notify_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue