summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qwindowspipereader.cpp
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2021-06-21 16:16:52 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2021-06-22 09:00:07 +0300
commit3fe44ddb9d94d3b2ab2b3a16c6ea13da5624dd1e (patch)
treea54350d9c98b6915a9991d3fd81c37a1af9c9691 /src/corelib/io/qwindowspipereader.cpp
parentd904274176d9b74dfedac1e3827cd2cc97693c41 (diff)
QWindowsPipeReader::read(): do not switch the mutex twice
We can get better performance if we omit unlocking the mutex before relocking it in startAsyncRead(). Change-Id: Ia012a71b95876d4f90c1dc4b7db5d7b267fca7a6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io/qwindowspipereader.cpp')
-rw-r--r--src/corelib/io/qwindowspipereader.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp
index b417b4fd50..539902c233 100644
--- a/src/corelib/io/qwindowspipereader.cpp
+++ b/src/corelib/io/qwindowspipereader.cpp
@@ -186,8 +186,9 @@ qint64 QWindowsPipeReader::bytesAvailable() const
*/
qint64 QWindowsPipeReader::read(char *data, qint64 maxlen)
{
- mutex.lock();
+ QMutexLocker locker(&mutex);
qint64 readSoFar;
+
// If startAsyncRead() has read data, copy it to its destination.
if (maxlen == 1 && actualReadBufferSize > 0) {
*data = readBuffer.getChar();
@@ -197,10 +198,9 @@ qint64 QWindowsPipeReader::read(char *data, qint64 maxlen)
readSoFar = readBuffer.read(data, qMin(actualReadBufferSize, maxlen));
actualReadBufferSize -= readSoFar;
}
- mutex.unlock();
if (!pipeBroken) {
- startAsyncRead();
+ startAsyncReadHelper(&locker);
if (readSoFar == 0)
return -2; // signal EWOULDBLOCK
}
@@ -223,7 +223,11 @@ bool QWindowsPipeReader::canReadLine() const
void QWindowsPipeReader::startAsyncRead()
{
QMutexLocker locker(&mutex);
+ startAsyncReadHelper(&locker);
+}
+void QWindowsPipeReader::startAsyncReadHelper(QMutexLocker<QMutex> *locker)
+{
if (readSequenceStarted || lastError != ERROR_SUCCESS)
return;
@@ -236,10 +240,10 @@ void QWindowsPipeReader::startAsyncRead()
if (!winEventActPosted) {
winEventActPosted = true;
- locker.unlock();
+ locker->unlock();
QCoreApplication::postEvent(this, new QEvent(QEvent::WinEventAct));
} else {
- locker.unlock();
+ locker->unlock();
}
SetEvent(syncHandle);