Fix mutex lock issues

This commit is contained in:
2026-04-13 19:48:32 +10:00
parent 56a8f09adf
commit 844d7396b2
30 changed files with 445 additions and 575 deletions

View File

@@ -31,6 +31,7 @@ namespace ANSCENTER
}
bool OPENVINOCL::LoadModel(const std::string& modelZipFilePath, const std::string& modelZipPassword) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
ModelLoadingGuard mlg(_modelLoading);
try {
bool result = ANSODBase::LoadModel(modelZipFilePath, modelZipPassword);
if (!result) return false;
@@ -78,6 +79,7 @@ namespace ANSCENTER
}
bool OPENVINOCL::LoadModelFromFolder(std::string licenseKey, ModelConfig modelConfig, std::string modelName, std::string className, const std::string& modelFolder, std::string& labelMap) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
ModelLoadingGuard mlg(_modelLoading);
try {
bool result = ANSODBase::LoadModelFromFolder(licenseKey, modelConfig, modelName, className, modelFolder, labelMap);
if (!result) return false;
@@ -173,6 +175,7 @@ namespace ANSCENTER
}
bool OPENVINOCL::Initialize(std::string licenseKey, ModelConfig modelConfig, const std::string& modelZipFilePath, const std::string& modelZipPassword, std::string& labelMap) {
std::lock_guard<std::recursive_mutex> lock(_mutex);
ModelLoadingGuard mlg(_modelLoading);
try {
std::string openVINOVersion = ov::get_openvino_version().buildNumber;
//this->_logger.LogDebug("OPENVINOCL::Initialize. OpenVINO version", openVINOVersion, __FILE__, __LINE__);
@@ -242,20 +245,7 @@ namespace ANSCENTER
}
std::vector<Object> OPENVINOCL::RunInference(const cv::Mat& input,const std::string& camera_id)
{
std::lock_guard<std::recursive_mutex> lock(_mutex);
// Early validation
if (!_licenseValid) {
_logger.LogError("OPENVINOCL::RunInference", "Invalid License",
__FILE__, __LINE__);
return {};
}
if (!_isInitialized) {
_logger.LogError("OPENVINOCL::RunInference", "Model is not initialized",
__FILE__, __LINE__);
return {};
}
if (!PreInferenceCheck("OPENVINOCL::RunInference")) return {};
if (input.empty() || input.cols < 20 || input.rows < 20) {
_logger.LogError("OPENVINOCL::RunInference", "Input image is invalid",