diff --git a/src/ScriptResolving/AngelScript/ContextPool.hpp b/src/ScriptResolving/AngelScript/ContextPool.hpp index c06b6fa..f8e84b1 100644 --- a/src/ScriptResolving/AngelScript/ContextPool.hpp +++ b/src/ScriptResolving/AngelScript/ContextPool.hpp @@ -18,19 +18,30 @@ class ContextPool { } }; + std::mutex Lock; ArbUt::Dictionary _pool; AngelScriptResolver* _resolver; AngelscriptUserdata* _userData; + CtxThreadedPoolStorage* CreateThreadPool(std::thread::id id) { + std::lock_guard guard(Lock); + auto tryGet = _pool.TryGet(id); + if (tryGet.has_value()) { + return tryGet->get(); + } + + auto p = new CtxThreadedPoolStorage(); + _pool.Insert(id, p); + return p; + } + CtxThreadedPoolStorage* GetThreadPool() { auto id = std::this_thread::get_id(); auto tryGet = _pool.TryGet(id); if (tryGet.has_value()) { return tryGet->get(); } - auto p = new CtxThreadedPoolStorage(); - _pool.Insert(id, p); - return p; + return CreateThreadPool(id); } public: