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 fs = std::filesystem;
|
||||||
|
|
||||||
namespace Crafter {
|
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) {
|
bool ModulePartition::Check(const fs::path& pcmDir) {
|
||||||
if(!checked) {
|
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")) {
|
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) {
|
for(ModulePartition* dependency : partitionDependencies) {
|
||||||
if(dependency->Check(pcmDir)) {
|
if(dependency->Check(pcmDir)) {
|
||||||
needsRecompiling = true;
|
needsRecompiling = true;
|
||||||
checked = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(Module* dependency : moduleDependencies) {
|
for(Module* dependency : moduleDependencies) {
|
||||||
if(dependency->Check(pcmDir)) {
|
if(dependency->Check(pcmDir)) {
|
||||||
needsRecompiling = true;
|
needsRecompiling = true;
|
||||||
checked = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
needsRecompiling = false;
|
needsRecompiling = false;
|
||||||
compiled.store(true);
|
compiled.store(true);
|
||||||
checked = true;
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
needsRecompiling = true;
|
needsRecompiling = true;
|
||||||
checked = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -60,7 +57,7 @@ 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) {
|
||||||
for(ModulePartition* dependency : partitionDependencies) {
|
for(ModulePartition* dependency : partitionDependencies) {
|
||||||
if(!dependency->compiled.load()) {
|
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);
|
dependency->compiled.wait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,11 +67,11 @@ namespace Crafter {
|
||||||
compiled.notify_all();
|
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::ifstream t(this->path);
|
||||||
std::stringstream buffer;
|
std::stringstream buffer;
|
||||||
buffer << t.rdbuf();
|
buffer << t.rdbuf();
|
||||||
|
|
@ -91,24 +88,27 @@ namespace Crafter {
|
||||||
|
|
||||||
bool Module::Check(const fs::path& pcmDir) {
|
bool Module::Check(const fs::path& pcmDir) {
|
||||||
if(!checked) {
|
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")) {
|
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) {
|
for(std::unique_ptr<ModulePartition>& partition : partitions) {
|
||||||
if(partition->Check(pcmDir)) {
|
if(partition->Check(pcmDir)) {
|
||||||
needsRecompiling = true;
|
depCheck = true;
|
||||||
checked = true;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
needsRecompiling = false;
|
if(depCheck) {
|
||||||
compiled.store(true);
|
needsRecompiling = true;
|
||||||
checked = true;
|
return true;
|
||||||
return false;
|
} else {
|
||||||
|
needsRecompiling = false;
|
||||||
|
compiled.store(true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for(std::unique_ptr<ModulePartition>& partition : partitions) {
|
for(std::unique_ptr<ModulePartition>& partition : partitions) {
|
||||||
partition->Check(pcmDir);
|
partition->Check(pcmDir);
|
||||||
}
|
}
|
||||||
needsRecompiling = true;
|
needsRecompiling = true;
|
||||||
checked = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
||||||
std::string libsString;
|
std::string libsString;
|
||||||
|
|
||||||
for(std::uint_fast32_t i = 0; i < depThreads.size(); i++) {
|
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")) {
|
if(config.dependencies[i].path.ends_with(".git")) {
|
||||||
fs::path name = fs::path(config.dependencies[i].path).filename();
|
fs::path name = fs::path(config.dependencies[i].path).filename();
|
||||||
name.replace_extension();
|
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";
|
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);
|
Project project = Project::LoadFromJSON(config.dependencies[i].path);
|
||||||
for(Configuration& depConfig : project.configurations) {
|
for(Configuration& depConfig : project.configurations) {
|
||||||
if(depConfig.name == config.dependencies[i].configuration){
|
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);
|
binDir = std::format("{}/{}", project.binDir.string(), config.name);
|
||||||
}
|
}
|
||||||
if(config.debug) {
|
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());
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue