From 683ddddc6ab5cd94376f1f116b981854f3a91c5b Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Fri, 24 Feb 2023 19:00:17 +0200 Subject: [PATCH] q_core_unix: move timspec<->chrono helpers from qtools_p.h Where it has a home with its other timespec/chrono siblings. Luckily I only needed to change one place in the code, and that source file already has #include's q_core_unix_p.h. Change-Id: I783383f958ceccfd6f9210f0b76d35b0f82b7cb5 Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemengine_unix.cpp | 3 +-- src/corelib/kernel/qcore_unix_p.h | 27 +++++++++++++++++++++-- src/corelib/kernel/qtimerinfo_unix.cpp | 2 +- src/corelib/tools/qtools_p.h | 23 ------------------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 1dbd2c8976d..3f07523f818 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #ifndef QT_BOOTSTRAPPED # include @@ -1559,7 +1558,7 @@ bool QFileSystemEngine::setFileTime(int fd, const QDateTime &newDate, QAbstractF if (time == QAbstractFileEngine::AccessTime || time == QAbstractFileEngine::ModificationTime) { const int idx = time == QAbstractFileEngine::AccessTime ? 0 : 1; const std::chrono::milliseconds msecs{newDate.toMSecsSinceEpoch()}; - ts[idx] = QtMiscUtils::durationToTimespec(msecs); + ts[idx] = durationToTimespec(msecs); } if (futimens(fd, ts) == -1) { diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index fe2e639d785..0705ee3bcd3 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -20,7 +20,6 @@ #include #include "qatomic.h" #include "qbytearray.h" -#include #ifndef Q_OS_UNIX # error "qcore_unix_p.h included on a non-Unix system" @@ -40,6 +39,7 @@ # include #endif +#include #include #include #include @@ -71,6 +71,29 @@ Q_DECLARE_TYPEINFO(pollfd, Q_PRIMITIVE_TYPE); static constexpr auto OneSecAsNsecs = std::chrono::nanoseconds(std::chrono::seconds{ 1 }).count(); +inline timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept +{ + using namespace std::chrono; + const seconds secs = duration_cast(timeout); + const nanoseconds frac = timeout - secs; + struct timespec ts; + ts.tv_sec = secs.count(); + ts.tv_nsec = frac.count(); + return ts; +} + +template +inline Duration timespecToChrono(struct timespec *ts) noexcept +{ + using namespace std::chrono; + return duration_cast(seconds{ts->tv_sec} + nanoseconds{ts->tv_nsec}); +} + +inline std::chrono::milliseconds timespecToChronoMs(struct timespec *ts) noexcept +{ + return timespecToChrono(ts); +} + // Internal operator functions for timespecs constexpr inline timespec &normalizedTimespec(timespec &t) { @@ -127,7 +150,7 @@ inline timeval timespecToTimeval(const timespec &ts) inline timespec &operator+=(timespec &t1, std::chrono::milliseconds msecs) { - t1 += QtMiscUtils::durationToTimespec(msecs); + t1 += durationToTimespec(msecs); return t1; } diff --git a/src/corelib/kernel/qtimerinfo_unix.cpp b/src/corelib/kernel/qtimerinfo_unix.cpp index 58801b2d601..2c52aaa1ac7 100644 --- a/src/corelib/kernel/qtimerinfo_unix.cpp +++ b/src/corelib/kernel/qtimerinfo_unix.cpp @@ -400,7 +400,7 @@ milliseconds QTimerInfoList::remainingDuration(int timerId) if (now < t->timeout) { // time to wait tm = roundToMillisecond(t->timeout - now); - return QtMiscUtils::timespecToChronoMs(&tm); + return timespecToChronoMs(&tm); } else { return milliseconds{0}; } diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h index 2c7ad6f0de0..db66f54d0aa 100644 --- a/src/corelib/tools/qtools_p.h +++ b/src/corelib/tools/qtools_p.h @@ -108,29 +108,6 @@ constexpr inline int qt_lencmp(qsizetype lhs, qsizetype rhs) noexcept /* else */ -1 ; } -inline timespec durationToTimespec(std::chrono::nanoseconds timeout) noexcept -{ - using namespace std::chrono; - const seconds secs = duration_cast(timeout); - const nanoseconds frac = timeout - secs; - struct timespec ts; - ts.tv_sec = secs.count(); - ts.tv_nsec = frac.count(); - return ts; -} - -template -inline Duration timespecToChrono(struct timespec *ts) noexcept -{ - using namespace std::chrono; - return duration_cast(seconds{ts->tv_sec} + nanoseconds{ts->tv_nsec}); -} - -inline std::chrono::milliseconds timespecToChronoMs(struct timespec *ts) noexcept -{ - return timespecToChrono(ts); -} - } // namespace QtMiscUtils // We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size.