diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2017-04-12 10:03:37 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2017-04-26 06:47:34 +0000 |
commit | a5ecc626bc6cf4e0890150acabcbff3a8d9af871 (patch) | |
tree | 2a3eb29fb73b63219904207c0eac6dd5da7df137 /src | |
parent | aa1ab248bd3dad450caabb445cd71874048d75b3 (diff) |
Increase buffer chunk sizes
This reduces the number of syscalls and thus the CPU load when dealing
with fast ports. And 32KiB seems still small enough to be no concern on
modern hardware even if it's excessive for a given port.
Change-Id: I4749e4255627d3abf2393323216e01ac6436413b
Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/serialport/qserialport.cpp | 5 | ||||
-rw-r--r-- | src/serialport/qserialport_p.h | 9 | ||||
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 2 | ||||
-rw-r--r-- | src/serialport/qserialport_win.cpp | 8 |
4 files changed, 13 insertions, 11 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp index fa780f3a..65fcfbb3 100644 --- a/src/serialport/qserialport.cpp +++ b/src/serialport/qserialport.cpp @@ -101,7 +101,7 @@ QSerialPortPrivate::QSerialPortPrivate() , isBreakEnabled(false) #if defined(Q_OS_WIN32) , handle(INVALID_HANDLE_VALUE) - , readChunkBuffer(ReadChunkSize, 0) + , readChunkBuffer(QSERIALPORT_BUFFERSIZE, 0) , communicationStarted(false) , writeStarted(false) , readStarted(false) @@ -121,7 +121,8 @@ QSerialPortPrivate::QSerialPortPrivate() , writeSequenceStarted(false) #endif { - writeBufferChunkSize = InitialBufferSize; + writeBufferChunkSize = QSERIALPORT_BUFFERSIZE; + readBufferChunkSize = QSERIALPORT_BUFFERSIZE; } void QSerialPortPrivate::setError(const QSerialPortErrorInfo &errorInfo) diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h index 7512da0e..a81cc4b6 100644 --- a/src/serialport/qserialport_p.h +++ b/src/serialport/qserialport_p.h @@ -97,6 +97,10 @@ struct serial_struct { # error Unsupported OS #endif +#ifndef QSERIALPORT_BUFFERSIZE +#define QSERIALPORT_BUFFERSIZE 32768 +#endif + QT_BEGIN_NAMESPACE class QWinOverlappedIoNotifier; @@ -120,11 +124,6 @@ class QSerialPortPrivate : public QIODevicePrivate { Q_DECLARE_PUBLIC(QSerialPort) public: - enum IoConstants { - ReadChunkSize = 512, - InitialBufferSize = 16384 - }; - QSerialPortPrivate(); bool open(QIODevice::OpenMode mode); diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 8f9f087a..0c79b476 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -769,7 +769,7 @@ bool QSerialPortPrivate::readNotification() // Always buffered, read data from the port into the read buffer qint64 newBytes = buffer.size(); - qint64 bytesToRead = ReadChunkSize; + qint64 bytesToRead = QSERIALPORT_BUFFERSIZE; if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - buffer.size())) { bytesToRead = readBufferMaxSize - buffer.size(); diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 43660ff7..67c68ee8 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -355,7 +355,7 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs) if (overlapped == &readCompletionOverlapped) { const qint64 readBytesForOneReadOperation = qint64(buffer.size()) - currentReadBufferSize; - if (readBytesForOneReadOperation == ReadChunkSize) { + if (readBytesForOneReadOperation == QSERIALPORT_BUFFERSIZE) { currentReadBufferSize = buffer.size(); } else if (readBytesForOneReadOperation == 0) { if (initialReadBufferSize != currentReadBufferSize) @@ -481,7 +481,7 @@ bool QSerialPortPrivate::completeAsyncRead(qint64 bytesTransferred) readStarted = false; bool result = true; - if (bytesTransferred == ReadChunkSize + if (bytesTransferred == QSERIALPORT_BUFFERSIZE || queuedBytesCount(QSerialPort::Input) > 0) { result = startAsyncRead(); } else if (readBufferMaxSize == 0 @@ -538,7 +538,7 @@ bool QSerialPortPrivate::startAsyncRead() if (readStarted) return true; - DWORD bytesToRead = ReadChunkSize; + DWORD bytesToRead = QSERIALPORT_BUFFERSIZE; if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - buffer.size())) { bytesToRead = readBufferMaxSize - buffer.size(); @@ -549,6 +549,8 @@ bool QSerialPortPrivate::startAsyncRead() } } + Q_ASSERT(int(bytesToRead) <= readChunkBuffer.size()); + ::ZeroMemory(&readCompletionOverlapped, sizeof(readCompletionOverlapped)); if (::ReadFile(handle, readChunkBuffer.data(), bytesToRead, nullptr, &readCompletionOverlapped)) { readStarted = true; |