summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qelapsedtimer_unix.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-08-12 12:54:11 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-25 05:41:14 +0200
commitcaa22ff8ad9ee85dadf1620a9be24c1d555c1973 (patch)
tree3a569e86e367b222e4cc82697dd4a73d859c86d3 /src/corelib/tools/qelapsedtimer_unix.cpp
parent88c7c35b21df302f3d3124ce26e79ec6429d3bde (diff)
Use nanosleep instead of pthread_cond_timedwait for thread sleeping
There's a comment saying nanosleep's availability is questionable, but the information of what systems don't have that is now lost in time. It's quite likely that they were older, Unix systems we no longer support anyway. nanosleep comes from POSIX.1b-1993, which is merged into POSIX.1-2001, so chances are that it's supported almost everywhere where Qt runs (except for Windows anyway). Change-Id: I4fd18f8715c43a42429000f3b3d2c3b7343f94b4 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'src/corelib/tools/qelapsedtimer_unix.cpp')
-rw-r--r--src/corelib/tools/qelapsedtimer_unix.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp
index d7419aea18..435a797a4d 100644
--- a/src/corelib/tools/qelapsedtimer_unix.cpp
+++ b/src/corelib/tools/qelapsedtimer_unix.cpp
@@ -144,6 +144,20 @@ timeval qt_gettime() Q_DECL_NOTHROW
return tv;
}
+void qt_nanosleep(timespec amount)
+{
+ // We'd like to use clock_nanosleep.
+ //
+ // But clock_nanosleep is from POSIX.1-2001 and both are *not*
+ // affected by clock changes when using relative sleeps, even for
+ // CLOCK_REALTIME.
+ //
+ // nanosleep is POSIX.1-1993
+
+ int r;
+ EINTR_LOOP(r, nanosleep(&amount, &amount));
+}
+
static qint64 elapsedAndRestart(qint64 sec, qint64 frac,
qint64 *nowsec, qint64 *nowfrac)
{