summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 51b55bf)
raw | patch | inline | side by side (parent: 51b55bf)
author | Ramsey Harris <ramsey@ti.com> | |
Fri, 13 Mar 2015 00:44:09 +0000 (17:44 -0700) | ||
committer | Robert Tivy <rtivy@ti.com> | |
Fri, 13 Mar 2015 23:34:17 +0000 (16:34 -0700) |
Split the given timeout value into seconds and microseconds.
Add these to the current time of day. Check for rollover on
the microseconds.
Add these to the current time of day. Check for rollover on
the microseconds.
linux/src/api/MessageQ.c | patch | blob | history |
index 53185fcdabfce7d44d74f0765cb577befcbe210d..b229e1b26193c28038929feeb2068fae1ec0ebdd 100644 (file)
--- a/linux/src/api/MessageQ.c
+++ b/linux/src/api/MessageQ.c
sem_wait(&obj->synchronizer);
}
else {
+ /* add timeout (microseconds) to current time of day */
gettimeofday(&tv, NULL);
+ tv.tv_sec += timeout / 1000000;
+ tv.tv_usec += timeout % 1000000;
+
+ if (tv.tv_usec >= 1000000) {
+ tv.tv_sec++;
+ tv.tv_usec -= 1000000;
+ }
+
+ /* set absolute timeout value */
ts.tv_sec = tv.tv_sec;
- ts.tv_nsec = (tv.tv_usec + timeout) * 1000;
+ ts.tv_nsec = tv.tv_usec * 1000; /* convert to nanoseconds */
if (sem_timedwait(&obj->synchronizer, &ts) < 0) {
if (errno == ETIMEDOUT) {
PRINTVERBOSE0("MessageQ_get: operation timed out\n")
-
- return MessageQ_E_TIMEOUT;
+ return (MessageQ_E_TIMEOUT);
+ }
+ else {
+ PRINTVERBOSE0("MessageQ_get: sem_timedwait error\n")
+ return (MessageQ_E_FAIL);
}
}
}