Fix mutex lock issues (OCR and FR)
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user