aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/deps/rpclib/include/rpc/detail/thread_group.h
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/deps/rpclib/include/rpc/detail/thread_group.h')
-rw-r--r--host/lib/deps/rpclib/include/rpc/detail/thread_group.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/host/lib/deps/rpclib/include/rpc/detail/thread_group.h b/host/lib/deps/rpclib/include/rpc/detail/thread_group.h
new file mode 100644
index 000000000..8905a7150
--- /dev/null
+++ b/host/lib/deps/rpclib/include/rpc/detail/thread_group.h
@@ -0,0 +1,40 @@
+#pragma once
+
+#ifndef THREAD_GROUP_H_MQSLWGKD
+#define THREAD_GROUP_H_MQSLWGKD
+
+#include <thread>
+#include <vector>
+
+namespace rpc {
+namespace detail {
+
+class thread_group {
+public:
+ thread_group() {}
+ thread_group(thread_group const &) = delete;
+
+ void create_threads(std::size_t thread_count, std::function<void()> func) {
+ for (std::size_t i = 0; i < thread_count; ++i) {
+ threads_.push_back(std::thread(func));
+ }
+ }
+
+ void join_all() {
+ for (auto &t : threads_) {
+ if (t.joinable()) {
+ t.join();
+ }
+ }
+ }
+
+ ~thread_group() { join_all(); }
+
+private:
+ std::vector<std::thread> threads_;
+};
+
+} /* detail */
+} /* rpc */
+
+#endif /* end of include guard: THREAD_GROUP_H_MQSLWGKD */