initialize NodeBuilder registry by IIFE instead of double lock pattern (#6753)

This commit is contained in:
Patryk Elszkowski 2021-07-27 06:53:29 +02:00 committed by GitHub
parent f5fe8550d9
commit 7bbf3775bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -393,20 +393,14 @@ namespace ngraph
AttributeVisitor& get_node_loader() { return *this; }
static FactoryRegistry<Node>& get_ops()
{
static std::shared_ptr<FactoryRegistry<Node>> registry;
static std::mutex init_guard;
if (!registry)
{
std::lock_guard<std::mutex> guard(init_guard);
if (!registry)
{
registry = std::make_shared<FactoryRegistry<Node>>();
#define NGRAPH_OP(NAME, NAMESPACE, VERSION) registry->register_factory<NAMESPACE::NAME>();
static FactoryRegistry<Node> registry = [] {
FactoryRegistry<Node> registry;
#define NGRAPH_OP(NAME, NAMESPACE, VERSION) registry.register_factory<NAMESPACE::NAME>();
#include "op_version_tbl.hpp"
#undef NGRAPH_OP
}
}
return *registry;
return registry;
}();
return registry;
}
protected: