diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-08-10 16:14:48 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-28 07:13:23 +0100 |
commit | bf5f2a9e3e3bf70c373b65bf95a332f4e1c514f9 (patch) | |
tree | ae2925a69f3f69854d7d0c30d2e51eee9dec321f /src/corelib/kernel/qcore_unix.cpp | |
parent | 5c5c9c26d299cd230dc48efcaaf3627861efa673 (diff) |
Switch to struct timespec everywhere instead of timeval
This avoids an extra division by 1000 when getting the current time.
This can't overflow, under normal circumstances, even on 32-bit: when
adding two values less than 1 billion, the result is less than 2
billion, which is less than 2^31.
Change-Id: I6f8e1aadfe2fcf6ac8da584eab4c1e61aee51cbb
Reviewed-by: David Faure (KDE) <faure@kde.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qcore_unix.cpp')
-rw-r--r-- | src/corelib/kernel/qcore_unix.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/corelib/kernel/qcore_unix.cpp b/src/corelib/kernel/qcore_unix.cpp index cc5479876d..5ab1d510ef 100644 --- a/src/corelib/kernel/qcore_unix.cpp +++ b/src/corelib/kernel/qcore_unix.cpp @@ -60,8 +60,8 @@ QT_BEGIN_NAMESPACE -static inline bool time_update(struct timeval *tv, const struct timeval &start, - const struct timeval &timeout) +static inline bool time_update(struct timespec *tv, const struct timespec &start, + const struct timespec &timeout) { if (!QElapsedTimer::isMonotonic()) { // we cannot recalculate the timeout without a monotonic clock as the time may have changed @@ -69,13 +69,13 @@ static inline bool time_update(struct timeval *tv, const struct timeval &start, } // clock source is monotonic, so we can recalculate how much timeout is left - struct timeval now = qt_gettime(); + struct timespec now = qt_gettime(); *tv = timeout + start - now; return tv->tv_sec >= 0; } int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, - const struct timeval *orig_timeout) + const struct timespec *orig_timeout) { if (!orig_timeout) { // no timeout -> block forever @@ -84,13 +84,13 @@ int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, return ret; } - timeval start = qt_gettime(); - timeval timeout = *orig_timeout; + timespec start = qt_gettime(); + timespec timeout = *orig_timeout; // loop and recalculate the timeout as needed int ret; forever { - ret = ::select(nfds, fdread, fdwrite, fdexcept, &timeout); + ret = ::pselect(nfds, fdread, fdwrite, fdexcept, &timeout, 0); if (ret != -1 || errno != EINTR) return ret; |