summaryrefslogtreecommitdiff
path: root/src/build.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2022-06-26 15:45:10 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2022-06-27 14:10:19 +0200
commit3d36cdfd6f71b0ed7c152003acf91e8432b78461 (patch)
tree6f30eb2b7f2f25087337f67929394e09b60bc997 /src/build.cc
parent2a55edcc40372403fb2de8ed20ed5c44464d416e (diff)
Diffstat (limited to 'src/build.cc')
-rw-r--r--src/build.cc36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/build.cc b/src/build.cc
index 98952e0..502c67c 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -52,8 +52,13 @@ int build(const Settings& settings,
std::list<std::future<int>> processes;
+ const auto start_interval = 50ms;
+ const auto poll_interval = 10ms;
+ auto last = std::chrono::system_clock::now() - start_interval;
+
// Start all tasks
bool done{false};
+ std::shared_ptr<Task> nextTask{};
while(!done)
{
bool started_one{false};
@@ -65,7 +70,14 @@ int build(const Settings& settings,
break;
}
- auto task = getNextTask(all_tasks, dirtyTasks);
+ if(!nextTask)
+ {
+ nextTask = getNextTask(all_tasks, dirtyTasks);
+ }
+
+ auto task = nextTask;
+ nextTask.reset();
+
if(task == nullptr)
{
if(processes.empty() && !dirtyTasks.empty())
@@ -77,6 +89,16 @@ int build(const Settings& settings,
break;
}
+ auto now = std::chrono::system_clock::now();
+ if(now - last < start_interval)
+ {
+ // Make sure we don't start tasks too close to each other to prevent
+ // straining the disk.
+ std::this_thread::sleep_for(start_interval - (now - last));
+ }
+
+ last = now;
+
processes.emplace_back(
std::async(std::launch::async,
[task]()
@@ -84,9 +106,11 @@ int build(const Settings& settings,
return task->run();
}));
started_one = true;
- // Make sure we don't start tasks on top of each other to prevent
- // straining the disk.
- std::this_thread::sleep_for(50ms);
+
+ //if(!nextTask)
+ //{
+ // nextTask = getNextTask(all_tasks, dirtyTasks);
+ //}
}
for(auto process = processes.begin();
@@ -108,9 +132,9 @@ int build(const Settings& settings,
break;
}
- if(!started_one) // prevent polling too fast if no task is yet ready
+ if(!started_one && nextTask) // prevent polling too fast if no task is yet ready
{
- std::this_thread::sleep_for(10ms);
+ std::this_thread::sleep_for(poll_interval);
}
}