MCPcopy Create free account
hub / github.com/ThePhD/sol2 / getInstance

Method getInstance

examples/source/singleton.cpp:30–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28};
29
30std::shared_ptr<SomeLib> SomeLib::getInstance() {
31 static std::weak_ptr<SomeLib> instance;
32 static std::mutex m;
33
34 m.lock();
35 auto ret = instance.lock();
36 if (!ret) {
37 ret.reset(new SomeLib());
38 instance = ret;
39 }
40 m.unlock();
41
42 return ret;
43}
44
45int main(int, char*[]) {
46 std::cout << "=== singleton ===" << std::endl;

Callers

nothing calls this directly

Calls 1

resetMethod · 0.45

Tested by

no test coverage detected