diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-07-21 09:40:28 +0200 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-07-28 06:47:03 +0200 |
commit | 2c67bbf6091477a09d280c322539cbaf1b6e4a8e (patch) | |
tree | 1128e37d5d397e3cb1d89aa01381463a5014842d /src/core/hle/service/sockets | |
parent | service/sockets: Add worker abstraction to execute blocking calls asynchronously (diff) | |
download | yuzu-2c67bbf6091477a09d280c322539cbaf1b6e4a8e.tar yuzu-2c67bbf6091477a09d280c322539cbaf1b6e4a8e.tar.gz yuzu-2c67bbf6091477a09d280c322539cbaf1b6e4a8e.tar.bz2 yuzu-2c67bbf6091477a09d280c322539cbaf1b6e4a8e.tar.lz yuzu-2c67bbf6091477a09d280c322539cbaf1b6e4a8e.tar.xz yuzu-2c67bbf6091477a09d280c322539cbaf1b6e4a8e.tar.zst yuzu-2c67bbf6091477a09d280c322539cbaf1b6e4a8e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/service/sockets/blocking_worker.h | 30 |
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 @@ #include <string_view> #include <thread> #include <variant> +#include <vector> #include <fmt/format.h> @@ -129,4 +130,33 @@ private: std::atomic_bool is_available{true}; }; +template <class Service, class... Types> +class BlockingWorkerPool { + using Worker = BlockingWorker<Service, Types...>; + +public: + explicit BlockingWorkerPool(Core::System& system_, Service* service_) + : system{system_}, service{service_} {} + + /// Returns a captured worker thread, creating new ones if necessary + Worker* CaptureWorker() { + for (auto& worker : workers) { + if (worker->TryCapture()) { + return worker.get(); + } + } + auto new_worker = Worker::Create(system, service, fmt::format("BSD:{}", workers.size())); + [[maybe_unused]] const bool success = new_worker->TryCapture(); + ASSERT(success); + + return workers.emplace_back(std::move(new_worker)).get(); + } + +private: + Core::System& system; + Service* const service; + + std::vector<std::unique_ptr<Worker>> workers; +}; + } // namespace Service::Sockets |