From 67a260d63f971a6dca2b8716a220831928661085 Mon Sep 17 00:00:00 2001 From: reduz Date: Mon, 18 Jul 2022 12:09:19 +0200 Subject: Implement a Worker ThreadPool This PR implements a worked thread pool. It uses a fixed amount of threads in a pool and allows scheduling tasks that can be run on threads (and then waited for). It satisfies the following use cases: * HTML5 thread count is fixed (and similar restrictions are known in consoles) so we need to reuse threads. * Thread spawning is slow in general, so reusing threads is faster anyway. * This implementation supports recursive waiting for tasks, making it less prone to deadlocks if threads from the pool also run tasks. After this is approved and merged, subsequent PRs will be needed to replace the ThreadWorkPool usage by this class. --- core/templates/safe_refcount.h | 1 + 1 file changed, 1 insertion(+) (limited to 'core/templates') diff --git a/core/templates/safe_refcount.h b/core/templates/safe_refcount.h index 3148283dca..1f6551762e 100644 --- a/core/templates/safe_refcount.h +++ b/core/templates/safe_refcount.h @@ -111,6 +111,7 @@ public: if (tmp >= p_value) { return tmp; // already greater, or equal } + if (value.compare_exchange_weak(tmp, p_value, std::memory_order_acq_rel)) { return p_value; } -- cgit v1.2.3