Fix model extract race issue to all classes

This commit is contained in:
2026-04-24 12:19:54 +10:00
parent baa88bcc48
commit e2bf17289d
51 changed files with 1252 additions and 148 deletions

View File

@@ -304,6 +304,15 @@ namespace ANSCENTER {
this->_logger.LogError("ANSALPR_CPU::Initialize. Output model folder is not exist", _modelFolder, __FILE__, __LINE__);
return false; // That means the model file is not exist or the password is not correct
}
// Serialize init against concurrent extract re-entries on the same
// folder. See ModelFolderLockGuard in Utility.h.
ANSCENTER::ModelFolderLockGuard _flg(_modelFolder, "ANSALPR_CPU::Initialize");
if (!_flg.acquired()) {
this->_logger.LogError("ANSALPR_CPU::Initialize",
"Timed out waiting for model-folder lock: " + _modelFolder,
__FILE__, __LINE__);
return false;
}
// 3. Load LD model
alprChecker.Init(MAX_ALPR_FRAME);
@@ -317,6 +326,15 @@ namespace ANSCENTER {
bool ANSALPR_CPU::LoadEngine() {
std::lock_guard<std::recursive_mutex> lock(_mutex);
try {
// Serialize init against concurrent extract re-entries on the same
// folder. See ModelFolderLockGuard in Utility.h.
ANSCENTER::ModelFolderLockGuard _flg(_modelFolder, "ANSALPR_CPU::LoadEngine");
if (!_flg.acquired()) {
this->_logger.LogError("ANSALPR_CPU::LoadEngine",
"Timed out waiting for model-folder lock: " + _modelFolder,
__FILE__, __LINE__);
return false;
}
// 1. Load license plate detection model (using CPU OpenVINO)
if (_lprDetector) _lprDetector.reset();
std::string lprModel = CreateFilePath(_modelFolder, "lprModel.xml");