diff options
author | Roland Reichwein <mail@reichwein.it> | 2024-05-03 21:03:06 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2024-05-03 21:03:06 +0200 |
commit | 45983abe664be648b513202c8c12578c9a85784f (patch) | |
tree | 37166e1f24219b84aab1c9e79d7743c8f59e9022 /ProcessRunner.h | |
parent | 6669794434cb9f472aafce126162b9b81389df5f (diff) |
Parallel build
Diffstat (limited to 'ProcessRunner.h')
-rw-r--r-- | ProcessRunner.h | 36 |
1 files changed, 36 insertions, 0 deletions
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 <deque> +#include <string> + +#include <boost/process.hpp> + +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<process> _processes; +}; + |