Skip to content
Snippets Groups Projects
Commit 21ea7cc4 authored by Martine Lenders's avatar Martine Lenders
Browse files

posix_semaphore: port to xtimer

parent d104cff2
No related branches found
No related tags found
No related merge requests found
......@@ -284,7 +284,7 @@ endif
ifneq (,$(filter posix_semaphore,$(USEMODULE)))
USEMODULE += sema
USEMODULE += vtimer
USEMODULE += xtimer
endif
ifneq (,$(filter sema,$(USEMODULE)))
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment