Browse Source

posix_semaphore: port to xtimer

cc430
Martine Lenders 7 years ago
parent
commit
21ea7cc4ae
  1. 2
      Makefile.dep
  2. 13
      sys/posix/semaphore/posix_semaphore.c

2
Makefile.dep

@ -284,7 +284,7 @@ endif
ifneq (,$(filter posix_semaphore,$(USEMODULE)))
USEMODULE += sema
USEMODULE += vtimer
USEMODULE += xtimer
endif
ifneq (,$(filter sema,$(USEMODULE)))

13
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;

Loading…
Cancel
Save