summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/sockets/blocking_worker.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/core/hle/service/sockets/blocking_worker.h b/src/core/hle/service/sockets/blocking_worker.h
index 7bd486530..31ef6b821 100644
--- a/src/core/hle/service/sockets/blocking_worker.h
+++ b/src/core/hle/service/sockets/blocking_worker.h
@@ -10,6 +10,7 @@
10#include <string_view> 10#include <string_view>
11#include <thread> 11#include <thread>
12#include <variant> 12#include <variant>
13#include <vector>
13 14
14#include <fmt/format.h> 15#include <fmt/format.h>
15 16
@@ -129,4 +130,33 @@ private:
129 std::atomic_bool is_available{true}; 130 std::atomic_bool is_available{true};
130}; 131};
131 132
133template <class Service, class... Types>
134class BlockingWorkerPool {
135 using Worker = BlockingWorker<Service, Types...>;
136
137public:
138 explicit BlockingWorkerPool(Core::System& system_, Service* service_)
139 : system{system_}, service{service_} {}
140
141 /// Returns a captured worker thread, creating new ones if necessary
142 Worker* CaptureWorker() {
143 for (auto& worker : workers) {
144 if (worker->TryCapture()) {
145 return worker.get();
146 }
147 }
148 auto new_worker = Worker::Create(system, service, fmt::format("BSD:{}", workers.size()));
149 [[maybe_unused]] const bool success = new_worker->TryCapture();
150 ASSERT(success);
151
152 return workers.emplace_back(std::move(new_worker)).get();
153 }
154
155private:
156 Core::System& system;
157 Service* const service;
158
159 std::vector<std::unique_ptr<Worker>> workers;
160};
161
132} // namespace Service::Sockets 162} // namespace Service::Sockets