summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-01-10 17:36:35 +0400
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-15 15:16:23 +0100
commit73823bcace62d8e168c81e9b083fcee5a1ba0ccc (patch)
treea1161518727645708deb604201040d12d730c8ab
parentf404826e695c3affb684f3185d74cd3a5b31efbc (diff)
downloadqtserialport-73823bcace62d8e168c81e9b083fcee5a1ba0ccc.tar.gz
Optimize access to the write buffer
Earlier for writing in writeBuffer was used the QSerialPortPrivate::writeToBuffer() method which contained a similar code for each platform. Therefore it is reasonable to delete this method, and to move its common functionality to the QSerialPort::writeData(). Also all platform-dependent code of start of data transfer move to the QSerialPortPrivate::startWriting() method. Change-Id: I1423723fd69c05df974f8ba597e3dd71d5a797dd Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport.cpp6
-rw-r--r--src/serialport/qserialport_symbian.cpp3
-rw-r--r--src/serialport/qserialport_symbian_p.h2
-rw-r--r--src/serialport/qserialport_unix.cpp14
-rw-r--r--src/serialport/qserialport_unix_p.h2
-rw-r--r--src/serialport/qserialport_win.cpp10
-rw-r--r--src/serialport/qserialport_win_p.h2
-rw-r--r--src/serialport/qserialport_wince.cpp10
8 files changed, 13 insertions, 36 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index 5d9442e..cd0c681 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -1375,7 +1375,11 @@ qint64 QSerialPort::readLineData(char *data, qint64 maxSize)
qint64 QSerialPort::writeData(const char *data, qint64 maxSize)
{
Q_D(QSerialPort);
- return d->writeToBuffer(data, maxSize);
+
+ ::memcpy(d->writeBuffer.reserve(maxSize), data, maxSize);
+ if (!d->writeBuffer.isEmpty())
+ d->startWriting();
+ return maxSize;
}
void QSerialPort::setError(QSerialPort::SerialPortError serialPortError, const QString &errorString)
diff --git a/src/serialport/qserialport_symbian.cpp b/src/serialport/qserialport_symbian.cpp
index 6047793..9318696 100644
--- a/src/serialport/qserialport_symbian.cpp
+++ b/src/serialport/qserialport_symbian.cpp
@@ -248,10 +248,9 @@ qint64 QSerialPortPrivate::systemOutputQueueSize () const
return 0;
}
-qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize)
+void QSerialPortPrivate::startWriting()
{
// TODO: Implement me
- return -1;
}
bool QSerialPortPrivate::waitForReadyRead(int msec)
diff --git a/src/serialport/qserialport_symbian_p.h b/src/serialport/qserialport_symbian_p.h
index 253aa11..7c3d3ef 100644
--- a/src/serialport/qserialport_symbian_p.h
+++ b/src/serialport/qserialport_symbian_p.h
@@ -72,7 +72,7 @@ public:
qint64 systemInputQueueSize () const;
qint64 systemOutputQueueSize () const;
- qint64 writeToBuffer(const char *data, qint64 maxSize);
+ void startWriting();
bool waitForReadyRead(int msec);
bool waitForBytesWritten(int msec);
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 9571767..b994a0e 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -414,20 +414,10 @@ qint64 QSerialPortPrivate::systemOutputQueueSize () const
return nbytes;
}
-qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize)
+void QSerialPortPrivate::startWriting()
{
- char *ptr = writeBuffer.reserve(maxSize);
- if (maxSize == 1)
- *ptr = *data;
- else
- ::memcpy(ptr, data, maxSize);
-
- const qint64 written = maxSize;
-
- if (!writeBuffer.isEmpty() && !isWriteNotificationEnabled())
+ if (!isWriteNotificationEnabled())
setWriteNotificationEnabled(true);
-
- return written;
}
bool QSerialPortPrivate::waitForReadyRead(int msecs)
diff --git a/src/serialport/qserialport_unix_p.h b/src/serialport/qserialport_unix_p.h
index dba0ac5..7dbb760 100644
--- a/src/serialport/qserialport_unix_p.h
+++ b/src/serialport/qserialport_unix_p.h
@@ -111,7 +111,7 @@ public:
qint64 systemInputQueueSize () const;
qint64 systemOutputQueueSize () const;
- qint64 writeToBuffer(const char *data, qint64 maxSize);
+ void startWriting();
bool waitForReadyRead(int msecs);
bool waitForBytesWritten(int msecs);
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index ecbfa39..f9e8a5e 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -354,18 +354,10 @@ qint64 QSerialPortPrivate::systemOutputQueueSize ()
#ifndef Q_OS_WINCE
-qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize)
+void QSerialPortPrivate::startWriting()
{
- char *ptr = writeBuffer.reserve(maxSize);
- if (maxSize == 1)
- *ptr = *data;
- else
- ::memcpy(ptr, data, maxSize);
-
if (!writeSequenceStarted)
startAsyncWrite();
-
- return maxSize;
}
bool QSerialPortPrivate::waitForReadyRead(int msecs)
diff --git a/src/serialport/qserialport_win_p.h b/src/serialport/qserialport_win_p.h
index 9876fe4..3ccdb56 100644
--- a/src/serialport/qserialport_win_p.h
+++ b/src/serialport/qserialport_win_p.h
@@ -81,7 +81,7 @@ public:
qint64 systemInputQueueSize ();
qint64 systemOutputQueueSize ();
- qint64 writeToBuffer(const char *data, qint64 maxSize);
+ void startWriting();
bool waitForReadyRead(int msec);
bool waitForBytesWritten(int msec);
diff --git a/src/serialport/qserialport_wince.cpp b/src/serialport/qserialport_wince.cpp
index 26ebf64..bb76465 100644
--- a/src/serialport/qserialport_wince.cpp
+++ b/src/serialport/qserialport_wince.cpp
@@ -253,18 +253,10 @@ bool QSerialPortPrivate::clear(QSerialPort::Directions directions)
return ::PurgeComm(descriptor, flags);
}
-qint64 QSerialPortPrivate::writeToBuffer(const char *data, qint64 maxSize)
+void QSerialPortPrivate::startWriting()
{
- char *ptr = writeBuffer.reserve(maxSize);
- if (maxSize == 1)
- *ptr = *data;
- else
- ::memcpy(ptr, data, maxSize);
-
// trigger write sequence
notifyWrite();
-
- return maxSize;
}
bool QSerialPortPrivate::waitForReadyRead(int msec)