summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2022-10-31 01:18:26 +0200
committerAhmad Samir <a.samirh78@gmail.com>2022-11-09 20:01:59 +0200
commitfee46831fd722935d126f8ab8f422911dbebb60f (patch)
tree355150db1b367a56459448b28928f0211a3baf76 /src/corelib/thread
parent7898de4258e06671feb84cfd0b746009b64f7f0d (diff)
QThread/Unix: use chrono for time arithmetic
Change-Id: I090d204db6126b3b6336637779b190509a9f0778 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthread_unix.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp
index 777aa362b2..8db27e8209 100644
--- a/src/corelib/thread/qthread_unix.cpp
+++ b/src/corelib/thread/qthread_unix.cpp
@@ -488,27 +488,31 @@ void QThread::yieldCurrentThread()
#endif // QT_CONFIG(thread)
-static timespec makeTimespec(time_t secs, long nsecs)
+static timespec makeTimespec(std::chrono::nanoseconds nsecs)
{
+ using namespace std::chrono;
+ const seconds secs = duration_cast<seconds>(nsecs);
+ const nanoseconds frac = nsecs - secs;
struct timespec ts;
- ts.tv_sec = secs;
- ts.tv_nsec = nsecs;
+ ts.tv_sec = secs.count();
+ ts.tv_nsec = frac.count();
return ts;
}
+
void QThread::sleep(unsigned long secs)
{
- qt_nanosleep(makeTimespec(secs, 0));
+ qt_nanosleep(makeTimespec(std::chrono::seconds{secs}));
}
void QThread::msleep(unsigned long msecs)
{
- qt_nanosleep(makeTimespec(msecs / 1000, msecs % 1000 * 1000 * 1000));
+ qt_nanosleep(makeTimespec(std::chrono::milliseconds{msecs}));
}
void QThread::usleep(unsigned long usecs)
{
- qt_nanosleep(makeTimespec(usecs / 1000 / 1000, usecs % (1000*1000) * 1000));
+ qt_nanosleep(makeTimespec(std::chrono::microseconds{usecs}));
}
#if QT_CONFIG(thread)