Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions drivermanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,12 @@ void DriverManger::enrollStop(QString actionId, ErrMsgInfo &errMsgInfo)
free(actionInfo.faceChara);
}
}

ModelManger::getSingleInstanceModel().unLoad();

QMetaObject::invokeMethod(m_spErollthread.data(),
"Stop",
qDebug() << "start Erollthread stop";
QMetaObject::invokeMethod(m_spErollthread.data(), "Stop",
Qt::BlockingQueuedConnection);
m_actionMap.remove(actionId);
ModelManger::getSingleInstanceModel().unLoad();
qDebug() << "ModelManger::unLoad";
auto charaList = m_spCharaDataManger->getCharaList();
setCharaList(charaList);

Expand Down
19 changes: 14 additions & 5 deletions workmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,19 @@ void ErollThread::run()
void ErollThread::Stop()
{
qDebug() << "ErollThread::Stop thread:" << QThread::currentThreadId();
disconnect(m_imageCapture.data(), &QImageCapture::readyForCaptureChanged, this, &ErollThread::readyForCapture);
disconnect(m_imageCapture.data(), &QImageCapture::imageCaptured, this, &ErollThread::processCapturedImage);
disconnect(m_imageCapture.data(), QOverload<int, QImageCapture::Error, const QString &>::of(&QImageCapture::errorOccurred),
this, &ErollThread::captureError);
m_stopCapture = true;
m_camera->stop();
m_camera.reset();
while (!m_checkDone) {
qDebug() << "wait check done thread:" << QThread::currentThreadId();
QThread::msleep(100);
Comment on lines +76 to +78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Busy-wait loop may block thread responsiveness.

Consider replacing the busy-wait loop with QWaitCondition or signals to avoid blocking the thread and improve responsiveness.

Suggested implementation:

    m_mutex.lock();
    while (!m_checkDone) {
        qDebug() << "wait check done thread:" << QThread::currentThreadId();
        m_checkDoneCondition.wait(&m_mutex, 100); // Wait for up to 100ms, then re-check
    }
    m_mutex.unlock();

You will need to:

  1. Add QWaitCondition m_checkDoneCondition; and QMutex m_mutex; as members of your ErollThread class.
  2. Wherever m_checkDone is set to true (likely in another thread), you must call:
    m_mutex.lock();
    m_checkDone = true;
    m_checkDoneCondition.wakeAll();
    m_mutex.unlock();
    
    This will wake up the waiting thread in Stop().
  3. Make sure to #include <QWaitCondition> and #include <QMutex> at the top of your file.

continue;
}
qDebug() << "check done";
close(m_fileSocket);
}

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

QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this);
connect(watcher, &QFutureWatcher<void>::finished, [this, watcher] {
m_checkDone = true;
watcher->deleteLater();
});
QFuture<void> future = QtConcurrent::run([=]() {
qDebug() << "thread id:" << QThread::currentThreadId();
QFuture<void> future = QtConcurrent::run([this, img]() {
auto guard = qScopeGuard([this]() {
this->m_checkDone = true;
});
QImage img1 = img.convertToFormat(QImage::Format_RGB888).rgbSwapped();
SeetaImageData image;
image.height = img1.height();
Expand Down Expand Up @@ -233,7 +243,6 @@ void ErollThread::processCapturedImage(int id, const QImage &preview)
if (status == seeta::FaceAntiSpoofing::SPOOF) {
QMetaObject::invokeMethod(this, "processStatus", Qt::QueuedConnection, Q_ARG(QString, m_actionId), Q_ARG(qint32, FaceEnrollNotRealHuman));
return;

} else {
qDebug() << "antispoofing ok";
}
Expand Down