From 45983abe664be648b513202c8c12578c9a85784f Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 3 May 2024 21:03:06 +0200 Subject: Parallel build --- ProcessRunner.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ProcessRunner.h (limited to 'ProcessRunner.h') diff --git a/ProcessRunner.h b/ProcessRunner.h new file mode 100644 index 0000000..1c0789d --- /dev/null +++ b/ProcessRunner.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include + +#include + +struct process +{ + process(const std::string& k, const std::string& command): key{k}, child{command} {} + std::string key; + boost::process::child child; +}; + +// runs a number of processes in parallel, with an upper limit +class ProcessRunner +{ +public: + ProcessRunner(); + + void spawn(const std::string& key, const std::string& command); + + bool empty(); // number of running processes is zero + bool full(); // number of running processes equals maximum + + int wait_one(std::string& key); // returns exit code, and key via reference + int wait_all(); + + size_t running(); // number of running processes in queue + size_t finished(); // number of finished processes in queue + +private: + int _max_number_of_processes; + std::deque _processes; +}; + -- cgit v1.2.3