summaryrefslogtreecommitdiffhomepage
path: root/ProcessRunner.h
diff options
context:
space:
mode:
Diffstat (limited to 'ProcessRunner.h')
-rw-r--r--ProcessRunner.h36
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;
+};
+