Commit 0bb940db authored by PanZezhong1725's avatar PanZezhong1725
Browse files

issue/461 make current runtime thread local

parent acb75f3b
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
namespace infinicore { namespace infinicore {
thread_local Runtime *ContextImpl::current_runtime_ = nullptr;
Runtime *ContextImpl::getCurrentRuntime() { Runtime *ContextImpl::getCurrentRuntime() {
return current_runtime_; return current_runtime_;
} }
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
namespace infinicore { namespace infinicore {
class ContextImpl { class ContextImpl {
private: private:
// Table of runtimes for every device (type and index)
std::array<std::vector<std::unique_ptr<Runtime>>, size_t(Device::Type::COUNT)> runtime_table_; std::array<std::vector<std::unique_ptr<Runtime>>, size_t(Device::Type::COUNT)> runtime_table_;
Runtime *current_runtime_ = nullptr; // Active runtime for current thread. Can use "static thread local" because context is a process singleton.
static thread_local Runtime *current_runtime_;
protected: protected:
ContextImpl(); ContextImpl();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment