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 <thiago.macieira@intel.com>
This commit is contained in:
parent
09f5bb9969
commit
683ddddc6a
@ -12,7 +12,6 @@
|
||||
#include <QtCore/qoperatingsystemversion.h>
|
||||
#include <QtCore/private/qcore_unix_p.h>
|
||||
#include <QtCore/private/qfiledevice_p.h>
|
||||
#include <QtCore/private/qtools_p.h>
|
||||
#include <QtCore/qvarlengtharray.h>
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
# include <QtCore/qstandardpaths.h>
|
||||
@ -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) {
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
#include "qatomic.h"
|
||||
#include "qbytearray.h"
|
||||
#include <QtCore/private/qtools_p.h>
|
||||
|
||||
#ifndef Q_OS_UNIX
|
||||
# error "qcore_unix_p.h included on a non-Unix system"
|
||||
@ -40,6 +39,7 @@
|
||||
# include <selectLib.h>
|
||||
#endif
|
||||
|
||||
#include <chrono>
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@ -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<seconds>(timeout);
|
||||
const nanoseconds frac = timeout - secs;
|
||||
struct timespec ts;
|
||||
ts.tv_sec = secs.count();
|
||||
ts.tv_nsec = frac.count();
|
||||
return ts;
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline Duration timespecToChrono(struct timespec *ts) noexcept
|
||||
{
|
||||
using namespace std::chrono;
|
||||
return duration_cast<Duration>(seconds{ts->tv_sec} + nanoseconds{ts->tv_nsec});
|
||||
}
|
||||
|
||||
inline std::chrono::milliseconds timespecToChronoMs(struct timespec *ts) noexcept
|
||||
{
|
||||
return timespecToChrono<std::chrono::milliseconds>(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;
|
||||
}
|
||||
|
||||
|
@ -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};
|
||||
}
|
||||
|
@ -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<seconds>(timeout);
|
||||
const nanoseconds frac = timeout - secs;
|
||||
struct timespec ts;
|
||||
ts.tv_sec = secs.count();
|
||||
ts.tv_nsec = frac.count();
|
||||
return ts;
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
inline Duration timespecToChrono(struct timespec *ts) noexcept
|
||||
{
|
||||
using namespace std::chrono;
|
||||
return duration_cast<Duration>(seconds{ts->tv_sec} + nanoseconds{ts->tv_nsec});
|
||||
}
|
||||
|
||||
inline std::chrono::milliseconds timespecToChronoMs(struct timespec *ts) noexcept
|
||||
{
|
||||
return timespecToChrono<std::chrono::milliseconds>(ts);
|
||||
}
|
||||
|
||||
} // namespace QtMiscUtils
|
||||
|
||||
// We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size.
|
||||
|
Loading…
x
Reference in New Issue
Block a user