Skip to content

Commit

Permalink
initialize NodeBuilder registry by IIFE instead of double lock pattern (
Browse files Browse the repository at this point in the history
  • Loading branch information
pelszkow authored Jul 27, 2021
1 parent f5fe855 commit 7bbf377
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions ngraph/test/util/visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7bbf377

Please sign in to comment.