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 and rnugmanx committed Aug 26, 2021
1 parent c859284 commit 2abb67e
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 2abb67e

Please sign in to comment.