summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Koenig <tobias.koenig@kdab.com>2015-07-02 15:18:10 +0200
committerTobias Koenig <tobias.koenig@kdab.com>2015-07-03 16:57:24 +0000
commit1c37490efc080593c2a1318e0c02f2f3c0b27dbf (patch)
tree371489eef46a81ff7343fb1bc2e88aad2382a41c
parentad8b9773a2f996e988d7b0c4dd439a3e21ca8c09 (diff)
downloadqtserialport-1c37490efc080593c2a1318e0c02f2f3c0b27dbf.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. Change-Id: Ic311a1cc5d2a1f9a1aec6750faddd396e448dd46 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport_wince.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp
index 25a1f07..1af45f1 100644
--- a/src/serialport/qserialport_wince.cpp
+++ b/src/serialport/qserialport_wince.cpp
@@ -83,21 +83,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().
@@ -131,7 +129,6 @@ private slots:
private:
QSerialPortPrivate *dptr;
- mutable bool running;
};
class WaitCommEventBreaker : public QThread
@@ -213,7 +210,9 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
void QSerialPortPrivate::close()
{
if (eventNotifier) {
- eventNotifier->deleteLater();
+ eventNotifier->terminate();
+ eventNotifier->wait();
+ delete eventNotifier;
eventNotifier = Q_NULLPTR;
}