From 889106af4d8381ac188a6532625e2c642150220f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 12 Jun 2021 15:53:20 +0200 Subject: Limit number of threads --- task.cc | 165 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 77 insertions(+), 88 deletions(-) (limited to 'task.cc') diff --git a/task.cc b/task.cc index 4dcbbd8..4728a1c 100644 --- a/task.cc +++ b/task.cc @@ -94,96 +94,85 @@ Task::Task(const BuildConfiguration& config, const Settings& settings, depsFile += ".d"; } -void Task::start() +int Task::run() { - future = - std::async(std::launch::async, - [&]() - { - if(!std::filesystem::exists(sourceFile)) - { - std::cout << "Missing source file: " << std::string(sourceFile) << "\n"; - return 1; - } - - bool recompile{false}; - - if(!recompile && - !std::filesystem::exists(targetFile)) - { - recompile = true; - std::cout << "Missing targetFile\n"; - } - - if(!recompile && - !std::filesystem::exists(depsFile)) - { - recompile = true; - std::cout << "Missing depsFile\n"; - } - - if(!recompile && - std::filesystem::last_write_time(sourceFile) > - std::filesystem::last_write_time(depsFile)) - { - recompile = true; - std::cout << "The sourceFile newer than depsFile\n"; - } - - if(!recompile) - { - auto depList = readDeps(depsFile); - for(const auto& dep : depList) - { - if(!std::filesystem::exists(dep) || - std::filesystem::last_write_time(targetFile) < - std::filesystem::last_write_time(dep)) - { - recompile = true; - std::cout << "The targetFile older than dep\n"; - break; - } - } - } - - if(!recompile && - std::filesystem::last_write_time(sourceFile) > - std::filesystem::last_write_time(targetFile)) - { - recompile = true; - std::cout << "The targetFile older than sourceFile\n"; - } - - if(recompile) - { - std::string comp = "g++"; - std::string flags = config.cxxflags; - if(std::string(sourceFile.extension()) == ".c") - { - comp = "gcc"; - flags = config.cflags; - } - std::string cmd = comp + - " -MMD -c " + std::string(sourceFile) + " " + - flags + " " + - "-o " + std::string(targetFile); - std::cout << cmd << "\n"; - - if(system(cmd.data())) - { - return 1; - } - return 0; - } - - return 0; - }); -} + if(!std::filesystem::exists(sourceFile)) + { + std::cout << "Missing source file: " << std::string(sourceFile) << "\n"; + return 1; + } -int Task::wait() -{ - future.wait(); - return future.get(); + bool recompile{false}; + + if(!recompile && + !std::filesystem::exists(targetFile)) + { + recompile = true; + //std::cout << "Missing targetFile\n"; + } + + if(!recompile && + !std::filesystem::exists(depsFile)) + { + recompile = true; + //std::cout << "Missing depsFile\n"; + } + + if(!recompile && + std::filesystem::last_write_time(sourceFile) > + std::filesystem::last_write_time(depsFile)) + { + recompile = true; + //std::cout << "The sourceFile newer than depsFile\n"; + } + + if(!recompile) + { + auto depList = readDeps(depsFile); + for(const auto& dep : depList) + { + if(!std::filesystem::exists(dep) || + std::filesystem::last_write_time(targetFile) < + std::filesystem::last_write_time(dep)) + { + recompile = true; + //std::cout << "The targetFile older than dep\n"; + break; + } + } + } + + if(!recompile && + std::filesystem::last_write_time(sourceFile) > + std::filesystem::last_write_time(targetFile)) + { + recompile = true; + //std::cout << "The targetFile older than sourceFile\n"; + } + + if(recompile) + { + std::string comp = "g++"; + std::string flags = config.cxxflags; + if(std::string(sourceFile.extension()) == ".c") + { + comp = "gcc"; + flags = config.cflags; + } + std::string cmd = comp + + " -MMD -c " + std::string(sourceFile) + " " + + flags + " " + + "-o " + std::string(targetFile); + std::cout << cmd << "\n"; + + if(system(cmd.data())) + { + return 1; + } + return 0; + } + + return 0; } int Task::clean() -- cgit v1.2.3