|
|
|
@ -25,7 +25,7 @@
|
|
|
|
|
#include "tcb.h" |
|
|
|
|
#include "timex.h" |
|
|
|
|
#include "thread.h" |
|
|
|
|
#include "vtimer.h" |
|
|
|
|
#include "xtimer.h" |
|
|
|
|
|
|
|
|
|
#define ENABLE_DEBUG (0) |
|
|
|
|
#include "debug.h" |
|
|
|
@ -34,15 +34,16 @@
|
|
|
|
|
|
|
|
|
|
int sem_timedwait(sem_t *sem, const struct timespec *abstime) |
|
|
|
|
{ |
|
|
|
|
timex_t now, timeout = { abstime->tv_sec, abstime->tv_nsec / USEC_IN_NS }; |
|
|
|
|
uint64_t now, timeout = (((uint64_t)abstime->tv_sec) * SEC_IN_USEC) + |
|
|
|
|
(abstime->tv_nsec / USEC_IN_NS); |
|
|
|
|
int res; |
|
|
|
|
vtimer_now(&now); |
|
|
|
|
if (timex_cmp(now, timeout) > 0) { |
|
|
|
|
now = xtimer_now64(); |
|
|
|
|
if (now > timeout) { |
|
|
|
|
errno = ETIMEDOUT; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
timeout = timex_sub(timeout, now); |
|
|
|
|
res = sema_wait_timed((sema_t *)sem, &timeout); |
|
|
|
|
timeout = timeout - now; |
|
|
|
|
res = sema_wait_timed((sema_t *)sem, timeout); |
|
|
|
|
if (res < 0) { |
|
|
|
|
errno = -res; |
|
|
|
|
return -1; |
|
|
|
|