Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[Core/Ref] Resolve coverity issues in registers_pool (#27854)

Tomasz Jankowskif5d2214a70a2
diff --git a/src/core/reference/include/openvino/reference/utils/registers_pool.hpp b/src/core/reference/include/openvino/reference/utils/registers_pool.hpp
index 62dfe01ec4e..4861ef4f7d9 100644
--- a/src/core/reference/include/openvino/reference/utils/registers_pool.hpp
+++ b/src/core/reference/include/openvino/reference/utils/registers_pool.hpp
@@ -64,7 +64,13 @@ public:
}
void release() {
if (auto pool = regPool.lock()) {
- pool->return_to_pool(reg);
+ try {
+ pool->return_to_pool(reg);
+ } catch (...) {
+ // This function is called by destructor and should not throw. Well formed Reg object won't cause
+ // any exception throw from return_to_pool, while on badly formed object the destructor is most
+ // likely called during exception stack unwind.
+ }
regPool.reset();
}
}
@@ -90,8 +96,10 @@ public:
RegistersPool::WeakPtr regPool;
};
+ static thread_local bool is_created;
+
virtual ~RegistersPool() {
- check_unique_and_update(false);
+ is_created = false;
}
template <ov::reference::jit::cpu_isa_t isa>
@@ -178,7 +186,7 @@ private:
}
}
- void check_unique_and_update(bool isCtor = true);
+ void check_unique_and_update();
PhysicalSet m_general_set;
PhysicalSet m_simd_set;
diff --git a/src/core/reference/src/utils/registers_pool.cpp b/src/core/reference/src/utils/registers_pool.cpp
index 413fdcc3ed8..a1e6462aa51 100644
--- a/src/core/reference/src/utils/registers_pool.cpp
+++ b/src/core/reference/src/utils/registers_pool.cpp
@@ -34,16 +34,12 @@ RegistersPool::RegistersPool(std::initializer_list<Xbyak::Reg> regsToExclude, in
m_general_set.exclude(Xbyak::Reg64(Xbyak::Operand::RSP));
}
-void RegistersPool::check_unique_and_update(bool is_ctor) {
- static thread_local bool is_created = false;
- if (is_ctor) {
- if (is_created) {
- OPENVINO_THROW("There should be only one instance of RegistersPool per thread");
- }
- is_created = true;
- } else {
- is_created = false;
- }
+thread_local bool RegistersPool::is_created = false;
+
+void RegistersPool::check_unique_and_update() {
+ OPENVINO_ASSERT(!is_created, "There should be only one instance of RegistersPool per thread");
+
+ is_created = true;
}
void RegistersPool::PhysicalSet::set_as_used(size_t reg_idx) {