Unverified Commit 53cef8b5 authored by Ivan Tikhonov's avatar Ivan Tikhonov Committed by GitHub

Fix unsafe opset singleton (#4483)

Signed-off-by: 's avatarAlexander Peskov <alexander.peskov@intel.com>
Co-authored-by: 's avatarAlexander Peskov <alexander.peskov@intel.com>
parent 1dbef5d3
...@@ -51,15 +51,17 @@ const ngraph::OpSet& ngraph::get_opset0() ...@@ -51,15 +51,17 @@ const ngraph::OpSet& ngraph::get_opset0()
const ngraph::OpSet& ngraph::get_opset1() const ngraph::OpSet& ngraph::get_opset1()
{ {
static std::mutex init_mutex; static std::mutex init_mutex;
static bool opset_is_initialized = false;
static OpSet opset; static OpSet opset;
if (opset.size() == 0) if (!opset_is_initialized)
{ {
std::lock_guard<std::mutex> guard(init_mutex); std::lock_guard<std::mutex> guard(init_mutex);
if (opset.size() == 0) if (!opset_is_initialized)
{ {
#define NGRAPH_OP(NAME, NAMESPACE) opset.insert<NAMESPACE::NAME>(); #define NGRAPH_OP(NAME, NAMESPACE) opset.insert<NAMESPACE::NAME>();
#include "ngraph/opsets/opset1_tbl.hpp" #include "ngraph/opsets/opset1_tbl.hpp"
#undef NGRAPH_OP #undef NGRAPH_OP
opset_is_initialized = true;
} }
} }
return opset; return opset;
...@@ -68,15 +70,17 @@ const ngraph::OpSet& ngraph::get_opset1() ...@@ -68,15 +70,17 @@ const ngraph::OpSet& ngraph::get_opset1()
const ngraph::OpSet& ngraph::get_opset2() const ngraph::OpSet& ngraph::get_opset2()
{ {
static std::mutex init_mutex; static std::mutex init_mutex;
static bool opset_is_initialized = false;
static OpSet opset; static OpSet opset;
if (opset.size() == 0) if (!opset_is_initialized)
{ {
std::lock_guard<std::mutex> guard(init_mutex); std::lock_guard<std::mutex> guard(init_mutex);
if (opset.size() == 0) if (!opset_is_initialized)
{ {
#define NGRAPH_OP(NAME, NAMESPACE) opset.insert<NAMESPACE::NAME>(); #define NGRAPH_OP(NAME, NAMESPACE) opset.insert<NAMESPACE::NAME>();
#include "ngraph/opsets/opset2_tbl.hpp" #include "ngraph/opsets/opset2_tbl.hpp"
#undef NGRAPH_OP #undef NGRAPH_OP
opset_is_initialized = true;
} }
} }
return opset; return opset;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment