Skip to content

Commit 5607633

Browse files
committed
fix: improve enrollment stop sequence and thread safety
1. Fixed thread synchronization issue by ensuring camera cleanup completes before proceeding 2. Added proper signal disconnections to prevent race conditions during stop 3. Implemented RAII pattern with CheckDoneGuard to ensure m_checkDone flag is always set 4. Reordered resource cleanup sequence for safer shutdown 5. Removed unnecessary QCoreApplication::processEvents() call that could cause reentrancy issues Log: Fixed enrollment process stop sequence to prevent application crashes Influence: 1. Test enrollment start and stop multiple times in quick succession 2. Verify camera resources are properly released after enrollment completion 3. Check that no race conditions occur during enrollment cancellation 4. Validate that face detection and anti-spoofing processes terminate cleanly 5. Test enrollment with different camera devices and configurations fix: 改进注册停止序列和线程安全性 1. 修复线程同步问题,确保相机清理完成后再继续执行 2. 添加正确的信号断开连接,防止停止过程中的竞争条件 3. 使用 CheckDoneGuard 实现 RAII 模式,确保 m_checkDone 标志始终被设置 4. 重新安排资源清理顺序以实现更安全的关闭 5. 移除可能导致重入问题的不必要 QCoreApplication::processEvents() 调用 Log: 修复注册过程停止序列,防止应用程序崩溃 Influence: 1. 测试快速连续多次启动和停止注册过程 2. 验证注册完成后相机资源是否正确释放 3. 检查注册取消过程中是否出现竞争条件 4. 验证人脸检测和活体检测过程是否干净终止 5. 使用不同的相机设备和配置测试注册功能 PMS: BUG-309915
1 parent 80a8804 commit 5607633

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

drivermanger.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,12 @@ void DriverManger::enrollStop(QString actionId, ErrMsgInfo &errMsgInfo)
116116
free(actionInfo.faceChara);
117117
}
118118
}
119-
120-
ModelManger::getSingleInstanceModel().unLoad();
121-
122-
QMetaObject::invokeMethod(m_spErollthread.data(),
123-
"Stop",
119+
qDebug() << "start Erollthread stop";
120+
QMetaObject::invokeMethod(m_spErollthread.data(), "Stop",
124121
Qt::BlockingQueuedConnection);
125122
m_actionMap.remove(actionId);
123+
ModelManger::getSingleInstanceModel().unLoad();
124+
qDebug() << "ModelManger::unLoad";
126125
auto charaList = m_spCharaDataManger->getCharaList();
127126
setCharaList(charaList);
128127

workmodule.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,19 @@ void ErollThread::run()
6666
void ErollThread::Stop()
6767
{
6868
qDebug() << "ErollThread::Stop thread:" << QThread::currentThreadId();
69+
disconnect(m_imageCapture.data(), &QImageCapture::readyForCaptureChanged, this, &ErollThread::readyForCapture);
70+
disconnect(m_imageCapture.data(), &QImageCapture::imageCaptured, this, &ErollThread::processCapturedImage);
71+
disconnect(m_imageCapture.data(), QOverload<int, QImageCapture::Error, const QString &>::of(&QImageCapture::errorOccurred),
72+
this, &ErollThread::captureError);
6973
m_stopCapture = true;
7074
m_camera->stop();
7175
m_camera.reset();
76+
while (!m_checkDone) {
77+
qDebug() << "wait check done thread:" << QThread::currentThreadId();
78+
QThread::msleep(100);
79+
continue;
80+
}
81+
qDebug() << "check done";
7282
close(m_fileSocket);
7383
}
7484

@@ -104,7 +114,6 @@ void ErollThread::sendCapture(QImage &img)
104114
while (countSize > 0 && !m_stopCapture) {
105115
long sendSize = write(m_fileSocket, &buf[size - countSize], static_cast<size_t>(countSize));
106116
if (sendSize < 0) {
107-
QCoreApplication::processEvents();
108117
continue;
109118
}
110119
countSize -= static_cast<unsigned long>(sendSize);
@@ -162,11 +171,12 @@ void ErollThread::processCapturedImage(int id, const QImage &preview)
162171

163172
QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this);
164173
connect(watcher, &QFutureWatcher<void>::finished, [this, watcher] {
165-
m_checkDone = true;
166174
watcher->deleteLater();
167175
});
168-
QFuture<void> future = QtConcurrent::run([=]() {
169-
qDebug() << "thread id:" << QThread::currentThreadId();
176+
QFuture<void> future = QtConcurrent::run([this, img]() {
177+
auto guard = qScopeGuard([this]() {
178+
this->m_checkDone = true;
179+
});
170180
QImage img1 = img.convertToFormat(QImage::Format_RGB888).rgbSwapped();
171181
SeetaImageData image;
172182
image.height = img1.height();
@@ -233,7 +243,6 @@ void ErollThread::processCapturedImage(int id, const QImage &preview)
233243
if (status == seeta::FaceAntiSpoofing::SPOOF) {
234244
QMetaObject::invokeMethod(this, "processStatus", Qt::QueuedConnection, Q_ARG(QString, m_actionId), Q_ARG(qint32, FaceEnrollNotRealHuman));
235245
return;
236-
237246
} else {
238247
qDebug() << "antispoofing ok";
239248
}

0 commit comments

Comments
 (0)