Fix mutex lock issues (OCR and FR)

This commit is contained in:
2026-04-13 20:38:40 +10:00
parent 844d7396b2
commit 8e60126c4c
16 changed files with 227 additions and 18 deletions

View File

@@ -44,6 +44,11 @@ namespace ANSCENTER {
const std::string& modelZipPassword,
std::string& labelMap)
{
struct LoadGuard {
std::atomic<bool>& f;
explicit LoadGuard(std::atomic<bool>& fl) : f(fl) { f.store(true); }
~LoadGuard() { f.store(false); }
} mlg(_modelLoading);
ANS_DBG("FaceRecognizer", "Initialize: modelZip=%s", modelZipFilePath.c_str());
bool result = ANSFRBase::Initialize(licenseKey, modelConfig, modelZipFilePath, modelZipPassword, labelMap);
if (!result) {
@@ -276,7 +281,9 @@ namespace ANSCENTER {
return embeddingResult;
}
std::lock_guard<std::recursive_mutex> lock(_mutex);
if (_modelLoading.load()) return embeddingResult;
auto lock = TryLockWithTimeout("ANSFaceRecognizer::Feature");
if (!lock.owns_lock()) return embeddingResult;
try {
if (engineType == EngineType::NVIDIA_GPU) {
@@ -338,7 +345,9 @@ namespace ANSCENTER {
return resultObjects;
}
std::lock_guard<std::recursive_mutex> lock(_mutex);
if (_modelLoading.load()) return resultObjects;
auto lock = TryLockWithTimeout("ANSFaceRecognizer::Match");
if (!lock.owns_lock()) return resultObjects;
if (!_isInitialized) {
_logger.LogError("ANSFaceRecognizer::Match",