解决退出时解码线程死锁问题

This commit is contained in:
Barry 2018-11-22 22:57:08 +08:00
parent 2f81e7372b
commit 3e906c51d3
2 changed files with 9 additions and 2 deletions

View file

@ -18,6 +18,9 @@ DeviceSocket::~DeviceSocket()
qint32 DeviceSocket::recvData(quint8 *buf, qint32 bufSize)
{
if (m_quit) {
return 0;
}
QMutexLocker locker(&m_mutex);
m_buffer = buf;
@ -63,6 +66,7 @@ void DeviceSocket::onReadyRead()
void DeviceSocket::quitNotify()
{
m_quit = true;
QMutexLocker locker(&m_mutex);
if (m_buffer) {
m_buffer = Q_NULLPTR;

View file

@ -18,10 +18,12 @@ public:
protected:
bool event(QEvent *event);
protected slots:
void onReadyRead();
public slots:
void quitNotify();
protected slots:
void onReadyRead();
private:
QMutex m_mutex;
QWaitCondition m_recvDataCond;
@ -29,6 +31,7 @@ private:
quint8* m_buffer = Q_NULLPTR;
qint32 m_bufferSize = 0;
qint32 m_dataSize = 0;
bool m_quit = false;
};
#endif // DEVICESOCKET_H