deadlock fix
This commit is contained in:
parent
72effdee9b
commit
ca25c838f5
3 changed files with 23 additions and 20 deletions
|
|
@ -24,32 +24,29 @@ 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) {}
|
||||
ModulePartition::ModulePartition(std::string&& name, fs::path&& path) : name(std::move(name)), path(std::move(path)), compiled(false), checked(false) {}
|
||||
|
||||
bool ModulePartition::Check(const fs::path& pcmDir) {
|
||||
if(!checked) {
|
||||
checked = true;
|
||||
if(fs::exists((pcmDir/path.filename()).generic_string()+".pcm") && fs::last_write_time(path.generic_string()+".cppm") < fs::last_write_time((pcmDir/path.filename()).generic_string()+".pcm")) {
|
||||
for(ModulePartition* dependency : partitionDependencies) {
|
||||
if(dependency->Check(pcmDir)) {
|
||||
needsRecompiling = true;
|
||||
checked = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for(Module* dependency : moduleDependencies) {
|
||||
if(dependency->Check(pcmDir)) {
|
||||
needsRecompiling = true;
|
||||
checked = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
needsRecompiling = false;
|
||||
compiled.store(true);
|
||||
checked = true;
|
||||
return false;
|
||||
} else {
|
||||
needsRecompiling = true;
|
||||
checked = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -60,7 +57,7 @@ namespace Crafter {
|
|||
void ModulePartition::Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir) {
|
||||
for(ModulePartition* dependency : partitionDependencies) {
|
||||
if(!dependency->compiled.load()) {
|
||||
//std::cout << std::format("{} is waiting on {}", name, dependency->name) << std::endl;
|
||||
//std::cout << std::format("{} is waiting on {} {}", name, dependency->name, dependency->needsRecompiling) << std::endl;
|
||||
dependency->compiled.wait(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -70,11 +67,11 @@ namespace Crafter {
|
|||
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) {}
|
||||
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) : name(std::move(name)), path(std::move(path)), compiled(false) {}
|
||||
Module::Module(std::string&& name, fs::path&& path) : name(std::move(name)), path(std::move(path)), compiled(false), checked(false) {}
|
||||
|
||||
Module::Module(fs::path&& path) : path(std::move(path)), compiled(false) {
|
||||
Module::Module(fs::path&& path) : path(std::move(path)), compiled(false), checked(false) {
|
||||
std::ifstream t(this->path);
|
||||
std::stringstream buffer;
|
||||
buffer << t.rdbuf();
|
||||
|
|
@ -91,24 +88,27 @@ namespace Crafter {
|
|||
|
||||
bool Module::Check(const fs::path& pcmDir) {
|
||||
if(!checked) {
|
||||
checked = true;
|
||||
if(fs::exists((pcmDir/path.filename()).generic_string()+".pcm") && fs::last_write_time(path.generic_string()+".cppm") < fs::last_write_time((pcmDir/path.filename()).generic_string()+".pcm")) {
|
||||
bool depCheck = false;
|
||||
for(std::unique_ptr<ModulePartition>& partition : partitions) {
|
||||
if(partition->Check(pcmDir)) {
|
||||
needsRecompiling = true;
|
||||
checked = true;
|
||||
return true;
|
||||
depCheck = true;
|
||||
}
|
||||
}
|
||||
needsRecompiling = false;
|
||||
compiled.store(true);
|
||||
checked = true;
|
||||
return false;
|
||||
if(depCheck) {
|
||||
needsRecompiling = true;
|
||||
return true;
|
||||
} else {
|
||||
needsRecompiling = false;
|
||||
compiled.store(true);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
for(std::unique_ptr<ModulePartition>& partition : partitions) {
|
||||
partition->Check(pcmDir);
|
||||
}
|
||||
needsRecompiling = true;
|
||||
checked = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue