Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/common/singleton/manager_impl.cc
Line
Count
Source
1
#include "source/common/singleton/manager_impl.h"
2
3
#include "envoy/registry/registry.h"
4
5
#include "source/common/common/assert.h"
6
#include "source/common/common/fmt.h"
7
8
namespace Envoy {
9
namespace Singleton {
10
11
49.5k
InstanceSharedPtr ManagerImpl::get(const std::string& name, SingletonFactoryCb cb) {
12
49.5k
  ASSERT(run_tid_ == thread_factory_.currentThreadId());
13
14
49.5k
  ENVOY_BUG(Registry::FactoryRegistry<Registration>::getFactory(name) != nullptr,
15
49.5k
            "invalid singleton name '" + name + "'. Make sure it is registered.");
16
17
49.5k
  if (nullptr == singletons_[name].lock()) {
18
41.4k
    InstanceSharedPtr singleton = cb();
19
41.4k
    singletons_[name] = singleton;
20
41.4k
    return singleton;
21
41.4k
  } else {
22
8.14k
    return singletons_[name].lock();
23
8.14k
  }
24
49.5k
}
25
26
} // namespace Singleton
27
} // namespace Envoy