summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2013-11-16 21:10:13 +0400
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-29 09:49:20 +0100
commit6c234760060b5b16cb089c59c69c7d38ceea9bc6 (patch)
treebfc685d29086649d416050e0c3fa15e91b20d647
parent7dcc5e422ce1ce3f29f52066f75f5dda3ffce5ef (diff)
downloadqtserialport-6c234760060b5b16cb089c59c69c7d38ceea9bc6.tar.gz
Optimization of the write notifier algorithm
The algorithm before the commit eca1a6d30a98861cb811cb2faf8d01334e60dd7c could process the write events from the several notifiers, which could be created in data transfer operation. But now the write notifier always is in one instance, so can do following optimizations: * The method lookupFreeWriteCompletionNotifier() now is renamed to the lookupWriteCompletionNotifier() and returns the pointer to the existing notifier without creating them (by analogy with others lookupXX() methods). * Now there is no need to control the write notifier state (to do enable or disable) in data transfer process. The current algorithm doesn't require it and the write notifier enabled once when port opens. * Use the open mode flag instead of low-level events mask to create the write notifiers. Also, this handling was added similarly to the read notifier. Tested the work with the terminal, the creader(a)sync, the cwriter(a)sync examples with Qt4 and then Qt5 on Windows 7/8 with use: * the virtual serial ports (the com0com project) * the physical on-board serial ports and the USB serial ports Change-Id: I8bc6a025a00dde986fde38c052d3ade4215938ec Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Laszlo Papp <lpapp@kde.org>
-rw-r--r--src/serialport/qserialport_win.cpp24
-rw-r--r--src/serialport/qserialport_win_p.h2
2 files changed, 11 insertions, 15 deletions
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index eef3d2b..078ec85 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -234,7 +234,6 @@ public:
: AbstractOverlappedEventNotifier(d, WriteCompletionEvent, false, parent) {}
bool processCompletionRoutine() Q_DECL_OVERRIDE {
- setEnabled(false);
DWORD numberOfBytesTransferred = 0;
if (!::GetOverlappedResult(dptr->descriptor, &o, &numberOfBytesTransferred, FALSE)) {
numberOfBytesTransferred = 0;
@@ -309,11 +308,16 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
if (!updateCommTimeouts())
return false;
- if (originalEventMask & EV_RXCHAR) {
+ if (mode & QIODevice::ReadOnly) {
QWinEventNotifier *n = new ReadOverlappedCompletionNotifier(this, q);
n->setEnabled(true);
}
+ if (mode & QIODevice::WriteOnly) {
+ QWinEventNotifier *n = new WriteOverlappedCompletionNotifier(this, q);
+ n->setEnabled(true);
+ }
+
QWinEventNotifier *n = new CommOverlappedEventNotifier(this, originalEventMask, q);
n->setEnabled(true);
@@ -712,14 +716,12 @@ bool QSerialPortPrivate::startAsyncWrite(int maxSize)
writeSequenceStarted = true;
- AbstractOverlappedEventNotifier *n = lookupFreeWriteCompletionNotifier();
+ AbstractOverlappedEventNotifier *n = lookupWriteCompletionNotifier();
if (!n) {
q->setError(QSerialPort::ResourceError);
return false;
}
- n->setEnabled(true);
-
initializeOverlappedStructure(*n->overlappedPointer());
if (::WriteFile(descriptor, ptr, nextSize, NULL, n->overlappedPointer()))
return true;
@@ -826,19 +828,13 @@ void QSerialPortPrivate::completeAsyncWrite(DWORD numberOfBytes)
startAsyncWrite(WriteChunkSize);
}
-AbstractOverlappedEventNotifier *QSerialPortPrivate::lookupFreeWriteCompletionNotifier()
+AbstractOverlappedEventNotifier *QSerialPortPrivate::lookupWriteCompletionNotifier()
{
- Q_Q(QSerialPort);
-
- // find first free not running write notifier
foreach (AbstractOverlappedEventNotifier *n, notifiers) {
- if ((n->type() == AbstractOverlappedEventNotifier::WriteCompletionEvent)
- && !n->isEnabled()) {
+ if (n->type() == AbstractOverlappedEventNotifier::WriteCompletionEvent)
return n;
- }
}
- // if all write notifiers in use, then create new write notifier
- return new WriteOverlappedCompletionNotifier(this, q);
+ return 0;
}
AbstractOverlappedEventNotifier *QSerialPortPrivate::lookupCommEventNotifier()
diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h
index bd164ff..a528f28 100644
--- a/src/serialport/qserialport_win_p.h
+++ b/src/serialport/qserialport_win_p.h
@@ -105,7 +105,7 @@ public:
bool startAsyncWrite(int maxSize = INT_MAX);
void completeAsyncRead(DWORD numberOfBytes);
void completeAsyncWrite(DWORD numberOfBytes);
- AbstractOverlappedEventNotifier *lookupFreeWriteCompletionNotifier();
+ AbstractOverlappedEventNotifier *lookupWriteCompletionNotifier();
AbstractOverlappedEventNotifier *lookupCommEventNotifier();
AbstractOverlappedEventNotifier *lookupReadCompletionNotifier();
#else