Lock guards for Angelscript ContextPool
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2022-02-26 20:22:00 +01:00
parent 6146a2b22e
commit fcc9988c3e
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 14 additions and 3 deletions

View File

@ -18,19 +18,30 @@ class ContextPool {
} }
}; };
std::mutex Lock;
ArbUt::Dictionary<std::thread::id, CtxThreadedPoolStorage*> _pool; ArbUt::Dictionary<std::thread::id, CtxThreadedPoolStorage*> _pool;
AngelScriptResolver* _resolver; AngelScriptResolver* _resolver;
AngelscriptUserdata* _userData; AngelscriptUserdata* _userData;
CtxThreadedPoolStorage* CreateThreadPool(std::thread::id id) {
std::lock_guard<std::mutex> 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() { CtxThreadedPoolStorage* GetThreadPool() {
auto id = std::this_thread::get_id(); auto id = std::this_thread::get_id();
auto tryGet = _pool.TryGet(id); auto tryGet = _pool.TryGet(id);
if (tryGet.has_value()) { if (tryGet.has_value()) {
return tryGet->get(); return tryGet->get();
} }
auto p = new CtxThreadedPoolStorage(); return CreateThreadPool(id);
_pool.Insert(id, p);
return p;
} }
public: public: