Lock guards for Angelscript ContextPool
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
6146a2b22e
commit
fcc9988c3e
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue