diff options
author | Max Kellermann <max@musicpd.org> | 2018-07-16 18:59:17 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-07-16 18:59:17 +0200 |
commit | bf5f12a51f6ea275582f31835ebe894ee0454bc9 (patch) | |
tree | 62798a3890e0e21b82d9f0a7bf707d358b4a24c7 | |
parent | c457d8e4425b8024f144ec37fb7d844d9fce1642 (diff) | |
parent | 866821765af714536fe60502cfab29a2a11d5c1c (diff) |
Merge branch 'patch-4' of git://github.com/Wang-Yue/MPD
-rw-r--r-- | src/thread/PosixCond.hxx | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/thread/PosixCond.hxx b/src/thread/PosixCond.hxx index e1c272071..c28147257 100644 --- a/src/thread/PosixCond.hxx +++ b/src/thread/PosixCond.hxx @@ -75,13 +75,13 @@ public: } private: - bool timed_wait(PosixMutex &mutex, unsigned timeout_ms) noexcept { + bool timed_wait(PosixMutex &mutex, uint_least32_t timeout_us) noexcept { struct timeval now; gettimeofday(&now, nullptr); struct timespec ts; - ts.tv_sec = now.tv_sec + timeout_ms / 1000; - ts.tv_nsec = (now.tv_usec + (timeout_ms % 1000) * 1000) * 1000; + ts.tv_sec = now.tv_sec + timeout_us / 1000000; + ts.tv_nsec = (now.tv_usec + (timeout_us % 1000000)) * 1000; // Keep tv_nsec < 1E9 to prevent return of EINVAL if (ts.tv_nsec >= 1000000000) { ts.tv_nsec -= 1000000000; @@ -94,13 +94,13 @@ private: public: bool timed_wait(PosixMutex &mutex, std::chrono::steady_clock::duration timeout) noexcept { - auto timeout_ms = std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count(); - if (timeout_ms < 0) - timeout_ms = 0; - else if (timeout_ms > std::numeric_limits<unsigned>::max()) - timeout_ms = std::numeric_limits<unsigned>::max(); + auto timeout_us = std::chrono::duration_cast<std::chrono::microseconds>(timeout).count(); + if (timeout_us < 0) + timeout_us = 0; + else if (timeout_us > std::numeric_limits<uint_least32_t>::max()) + timeout_us = std::numeric_limits<uint_least32_t>::max(); - return timed_wait(mutex, timeout_ms); + return timed_wait(mutex, timeout_us); } }; |