diff --git a/Makefile.dep b/Makefile.dep index 29776529fb..770d23614c 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -284,7 +284,7 @@ endif ifneq (,$(filter posix_semaphore,$(USEMODULE))) USEMODULE += sema - USEMODULE += vtimer + USEMODULE += xtimer endif ifneq (,$(filter sema,$(USEMODULE))) diff --git a/sys/posix/semaphore/posix_semaphore.c b/sys/posix/semaphore/posix_semaphore.c index 5db5673797..d1152ef686 100644 --- a/sys/posix/semaphore/posix_semaphore.c +++ b/sys/posix/semaphore/posix_semaphore.c @@ -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;