summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-12-08 19:28:16 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2016-12-08 19:28:16 +0100
commit18b3c71d48c131d34c15dd9e81692ff2622bff37 (patch)
tree00dbc9bd85bc498f8602400065329eff4018d746 /src
parenta691fa7fca30fb6e964c50b9001ab48018754218 (diff)
Alternative approach to semaphore timed wait.
Diffstat (limited to 'src')
-rw-r--r--src/semaphore.cc10
1 files changed, 2 insertions, 8 deletions
diff --git a/src/semaphore.cc b/src/semaphore.cc
index 42c9aec..51014b3 100644
--- a/src/semaphore.cc
+++ b/src/semaphore.cc
@@ -119,18 +119,12 @@ bool Semaphore::wait(const std::chrono::milliseconds& timeout)
}
#else
struct timespec ts;
-
- struct timeval now;
- int rv = gettimeofday(&now, nullptr);
- assert(rv == 0);
-
- ts.tv_sec = now.tv_sec;
- ts.tv_nsec = now.tv_usec * 1000;
+ clock_gettime(CLOCK_REALTIME, &ts);
// Add timeout
time_t seconds = (time_t)(timeout.count() / 1000);
ts.tv_sec += seconds;
- ts.tv_nsec += (long)((timeout.count() - (seconds * 1000)) * 1000000);
+ ts.tv_nsec += (long)((timeout.count() % 1000) * 1000000);
// Make sure we don't overflow the nanoseconds.
constexpr long nsec = 1000000000LL;