summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qtimestamp_mac.cpp109
-rw-r--r--src/corelib/tools/tools.pri3
2 files changed, 111 insertions, 1 deletions
diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp
new file mode 100644
index 0000000..bdc91d1
--- /dev/null
+++ b/src/corelib/tools/qtimestamp_mac.cpp
@@ -0,0 +1,109 @@
+/****************************************************************************
+**
+** 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"
+#include <sys/time.h>
+#include <unistd.h>
+
+#include <mach/mach_time.h>
+
+QT_BEGIN_NAMESPACE
+
+bool QTimestamp::isMonotonic()
+{
+ return true;
+}
+
+static mach_timebase_info_data_t info = {0,0};
+static qint64 absoluteToMSecs(qint64 cpuTime)
+{
+ if (info.denom == 0)
+ mach_timebase_info(&info);
+ qint64 nsecs = cpuTime * info.numer / info.denom;
+ return nsecs / (1000*1000ull);
+}
+
+static qint64 msecsToAbsolute(qint64 ms)
+{
+ if (info.denom == 0)
+ mach_timebase_info(&info);
+ qint64 nsecs = ms * 1000000ull;
+ return nsecs * info.denom / info.numer;
+}
+
+void QTimestamp::start()
+{
+ t1 = mach_absolute_time();
+ t2 = 0;
+}
+
+qint64 QTimestamp::elapsed() const
+{
+ uint64_t cpu_time = mach_absolute_time();
+ return absoluteToMSecs(cpu_time - t1);
+}
+
+qint64 QTimestamp::msecsTo(const QTimestamp &other) const
+{
+ return absoluteToMSecs(other.t1 - t1);
+}
+
+void QTimestamp::addMSecs(int ms)
+{
+ t1 += msecsToAbsolute(ms);
+}
+
+qint64 QTimestamp::secsTo(const QTimestamp &other) const
+{
+ return msecsTo(other) / 1000;
+}
+
+void QTimestamp::addSecs(int secs)
+{
+ t1 += secs * 1000;
+}
+
+bool operator<(const QTimestamp &v1, const QTimestamp &v2)
+{
+ return v1.t1 < v2.t1;
+}
+
+QT_END_NAMESPACE
diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri
index 49f2f16..3599cc7 100644
--- a/src/corelib/tools/tools.pri
+++ b/src/corelib/tools/tools.pri
@@ -82,7 +82,8 @@ SOURCES += \
symbian:SOURCES+=tools/qlocale_symbian.cpp
-unix:SOURCES += tools/qtimestamp_generic.cpp
+mac:SOURCES += tools/qtimestamp_mac.cpp
+else:SOURCES += tools/qtimestamp_generic.cpp
#zlib support
contains(QT_CONFIG, zlib) {