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;
AngelScriptResolver* _resolver;
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() {
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: