1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

posix_semaphore: port to xtimer

This commit is contained in:
Martine Lenders 2015-10-25 15:53:26 +01:00
parent d104cff214
commit 21ea7cc4ae
2 changed files with 8 additions and 7 deletions

View File

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

View File

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