summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-02-18 18:47:10 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-03-17 10:54:16 (GMT)
commit8c9446cd2058fde086df92f6b7d97e4770cf8dc6 (patch)
tree8118b5640a7495ccd53ff323983c1edfe67e2fe5 /src
parent49d949b644b94fbd6c1946ffddcc1b8675ffa9ef (diff)
downloadQt-8c9446cd2058fde086df92f6b7d97e4770cf8dc6.zip
Qt-8c9446cd2058fde086df92f6b7d97e4770cf8dc6.tar.gz
Qt-8c9446cd2058fde086df92f6b7d97e4770cf8dc6.tar.bz2
Add a qtimestamp.cpp with some common functions.
Had to add invalidate() and isValid() functions because that's what QUnifiedTimer expects (QAbstractAnimation). Also move restart() to each implementation for efficiency. Task-number: QT-2965
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qtimestamp.cpp65
-rw-r--r--src/corelib/tools/qtimestamp.h16
-rw-r--r--src/corelib/tools/qtimestamp_generic.cpp8
-rw-r--r--src/corelib/tools/qtimestamp_mac.cpp8
-rw-r--r--src/corelib/tools/qtimestamp_unix.cpp13
-rw-r--r--src/corelib/tools/qtimestamp_win.cpp7
-rw-r--r--src/corelib/tools/tools.pri1
7 files changed, 106 insertions, 12 deletions
diff --git a/src/corelib/tools/qtimestamp.cpp b/src/corelib/tools/qtimestamp.cpp
new file mode 100644
index 0000000..b861099
--- /dev/null
+++ b/src/corelib/tools/qtimestamp.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qtimestamp.h"
+
+QT_BEGIN_NAMESPACE
+
+static const qint64 invalidData = Q_INT64_C(0x8000000000000000);
+
+void QTimestamp::invalidate()
+{
+ t1 = t2 = invalidData;
+}
+
+bool QTimestamp::isValid() const
+{
+ return t1 != invalidData && t2 != invalidData;
+}
+
+bool QTimestamp::hasExpired(qint64 timeout) const
+{
+ // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be
+ // considered as never expired
+ return quint64(elapsed()) > quint64(timeout);
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/tools/qtimestamp.h b/src/corelib/tools/qtimestamp.h
index f923cd4..1e913f0 100644
--- a/src/corelib/tools/qtimestamp.h
+++ b/src/corelib/tools/qtimestamp.h
@@ -56,20 +56,12 @@ public:
static bool isMonotonic();
void start();
- qint64 restart()
- {
- qint64 r = elapsed();
- start();
- return r;
- }
+ qint64 restart();
+ void invalidate();
+ bool isValid() const;
qint64 elapsed() const;
- bool hasExpired(qint64 timeout) const
- {
- // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be
- // considered as never expired
- return quint64(elapsed()) > quint64(timeout);
- }
+ bool hasExpired(qint64 timeout) const;
qint64 msecsTo(const QTimestamp &other) const;
void addMSecs(int ms);
diff --git a/src/corelib/tools/qtimestamp_generic.cpp b/src/corelib/tools/qtimestamp_generic.cpp
index 18c5026..9930932 100644
--- a/src/corelib/tools/qtimestamp_generic.cpp
+++ b/src/corelib/tools/qtimestamp_generic.cpp
@@ -56,6 +56,14 @@ void QTimestamp::start()
t2 = 0;
}
+qint64 QTimestamp::restart()
+{
+ QTime t = QTime::currentTime();
+ qint64 old = t1;
+ t1 = t.mds;
+ return t1 - old;
+}
+
qint64 QTimestamp::elapsed() const
{
QTime t = QTime::currentTime();
diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp
index e1a7d79..a80e7ee 100644
--- a/src/corelib/tools/qtimestamp_mac.cpp
+++ b/src/corelib/tools/qtimestamp_mac.cpp
@@ -90,6 +90,14 @@ void QTimestamp::start()
t2 = 0;
}
+qint64 QTimestamp::restart()
+{
+ qint64 old = t1;
+ t1 = mach_absolute_time();
+
+ return absoluteToMSecs(t1 - old);
+}
+
qint64 QTimestamp::elapsed() const
{
uint64_t cpu_time = mach_absolute_time();
diff --git a/src/corelib/tools/qtimestamp_unix.cpp b/src/corelib/tools/qtimestamp_unix.cpp
index dbf49c1..75371e7 100644
--- a/src/corelib/tools/qtimestamp_unix.cpp
+++ b/src/corelib/tools/qtimestamp_unix.cpp
@@ -129,6 +129,19 @@ void QTimestamp::start()
t2 = r.second;
}
+qint64 QTimestamp::restart()
+{
+ QPair<long, long> r = do_gettime();
+ qint64 oldt1 = t1;
+ qint64 oldt2 = t2;
+ t1 = r.first;
+ t2 = r.second;
+
+ r.first -= oldt1;
+ r.second -= oldt2;
+ return r.first * 1000 + r.second / fractionAdjustment();
+}
+
qint64 QTimestamp::elapsed() const
{
QTimestamp now;
diff --git a/src/corelib/tools/qtimestamp_win.cpp b/src/corelib/tools/qtimestamp_win.cpp
index 99faebd..72d38d0 100644
--- a/src/corelib/tools/qtimestamp_win.cpp
+++ b/src/corelib/tools/qtimestamp_win.cpp
@@ -87,6 +87,13 @@ void QTimestamp::start()
t2 = 0;
}
+qint64 QTimestamp::restart()
+{
+ qint64 oldt1 = t1;
+ t1 = getTickCount();
+ return t1 - oldt1;
+}
+
qint64 QTimestamp::elapsed() const
{
return getTickCount() - t1;
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index 863f86e..e1097c4 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -77,6 +77,7 @@ SOURCES += \
tools/qstringlist.cpp \
tools/qtextboundaryfinder.cpp \
tools/qtimeline.cpp \
+ tools/qtimestamp.cpp \
tools/qvector.cpp \
tools/qvsnprintf.cpp