/proc/self/cwd/source/common/singleton/manager_impl.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #include "envoy/singleton/manager.h" |
4 | | #include "envoy/thread/thread.h" |
5 | | |
6 | | #include "source/common/common/non_copyable.h" |
7 | | |
8 | | #include "absl/container/node_hash_map.h" |
9 | | |
10 | | namespace Envoy { |
11 | | namespace Singleton { |
12 | | |
13 | | /** |
14 | | * Implementation of the singleton manager that checks the registry for name validity. It is |
15 | | * assumed the singleton manager is only used on the main thread so it is not thread safe. Asserts |
16 | | * verify that. |
17 | | */ |
18 | | class ManagerImpl : public Manager, NonCopyable { |
19 | | public: |
20 | | explicit ManagerImpl(Thread::ThreadFactory& thread_factory) |
21 | 72.0k | : thread_factory_(thread_factory), run_tid_(thread_factory.currentThreadId()) {} |
22 | | |
23 | | // Singleton::Manager |
24 | | InstanceSharedPtr get(const std::string& name, SingletonFactoryCb cb) override; |
25 | | |
26 | | private: |
27 | | absl::node_hash_map<std::string, std::weak_ptr<Instance>> singletons_; |
28 | | Thread::ThreadFactory& thread_factory_; |
29 | | const Thread::ThreadId run_tid_; |
30 | | }; |
31 | | |
32 | | } // namespace Singleton |
33 | | } // namespace Envoy |