diff options
author | Tobias Koenig <tobias.koenig@kdab.com> | 2015-07-02 15:18:10 +0200 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2015-07-04 13:05:24 +0000 |
commit | 0a4d469631eb5af3a6169757f53843900c9ffd44 (patch) | |
tree | 6cd857126f20f91b005d2146fd4c76d4f140dc8f /src/serialport | |
parent | e2cbf244cbf58211a5d9808a285f878e92d21291 (diff) | |
download | qtserialport-0a4d469631eb5af3a6169757f53843900c9ffd44.tar.gz |
WinCE: Fix closing the serial port
Terminate the notifier thread instead of relying
that the 'running' member variable is evaluated.
Most of the time, the notifier thread is blocked
inside the ::WaitCommEvent() call, so even if the
main thread requests a close by setting 'running'
to false, the condition of the while loop is not
evaluated until some data come in on the serial
line, which might not happen in an acceptable time
frame.
WinCE supports proper termination of threads, so
there shouldn't be a problem with the new approach.
The code was tested on a WinCE7 system, closing and
reopening QSerialPort works as expected now.
(cherry-picked from 1c37490efc080593c2a1318e0c02f2f3c0b27dbf)
Change-Id: Ic311a1cc5d2a1f9a1aec6750faddd396e448dd46
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/serialport')
-rw-r--r-- | src/serialport/qserialport_wince.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp index 72e1652..86bb83f 100644 --- a/src/serialport/qserialport_wince.cpp +++ b/src/serialport/qserialport_wince.cpp @@ -91,21 +91,19 @@ signals: public: CommEventNotifier(DWORD mask, QSerialPortPrivate *d, QObject *parent) - : QThread(parent), dptr(d), running(true) { + : QThread(parent), dptr(d) { connect(this, SIGNAL(eventMask(quint32)), this, SLOT(processNotification(quint32))); ::SetCommMask(dptr->handle, mask); } virtual ~CommEventNotifier() { - running = false; ::SetCommMask(dptr->handle, 0); - wait(); } protected: void run() Q_DECL_OVERRIDE { DWORD mask = 0; - while (running) { + while (true) { if (::WaitCommEvent(dptr->handle, &mask, FALSE)) { // Wait until complete the operation changes the port settings, // see updateDcb(). @@ -139,7 +137,6 @@ private slots: private: QSerialPortPrivate *dptr; - mutable bool running; }; class WaitCommEventBreaker : public QThread @@ -229,7 +226,9 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) void QSerialPortPrivate::close() { if (eventNotifier) { - eventNotifier->deleteLater(); + eventNotifier->terminate(); + eventNotifier->wait(); + delete eventNotifier; eventNotifier = Q_NULLPTR; } |