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 {
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
|||
std::string libsString;
|
||||
|
||||
for(std::uint_fast32_t i = 0; i < depThreads.size(); i++) {
|
||||
depThreads[i] = std::thread([i, &config, &libMutex, &depLibSet, &buildDir, &pcmDir, &libsString, &binDir](){
|
||||
depThreads[i] = std::thread([i, &config, &libMutex, &depLibSet, &buildDir, &pcmDir, &libsString, &binDir, this](){
|
||||
if(config.dependencies[i].path.ends_with(".git")) {
|
||||
fs::path name = fs::path(config.dependencies[i].path).filename();
|
||||
name.replace_extension();
|
||||
|
|
@ -194,6 +194,9 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
|||
}
|
||||
config.dependencies[i].path = fs::path(config.dependencies[i].path).filename().replace_extension()/"project.json";
|
||||
}
|
||||
if(fs::path(config.dependencies[i].path).is_relative()) {
|
||||
config.dependencies[i].path = this->path/config.dependencies[i].path;
|
||||
}
|
||||
Project project = Project::LoadFromJSON(config.dependencies[i].path);
|
||||
for(Configuration& depConfig : project.configurations) {
|
||||
if(depConfig.name == config.dependencies[i].configuration){
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ int main(int argc, char* argv[]) {
|
|||
binDir = std::format("{}/{}", project.binDir.string(), config.name);
|
||||
}
|
||||
if(config.debug) {
|
||||
system(std::format("cd {} && ./{}", (fs::path(projectPath).parent_path()/binDir).string(), project.name).c_str());
|
||||
} else {
|
||||
system(std::format("cd {} && lldb -o run {}", (fs::path(projectPath).parent_path()/binDir).string(), project.name).c_str());
|
||||
} else {
|
||||
system(std::format("cd {} && ./{}", (fs::path(projectPath).parent_path()/binDir).string(), project.name).c_str());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue