From 29d84a6865a0431792d45695b3425e2b0ae5675e Mon Sep 17 00:00:00 2001 From: smlng Date: Wed, 21 Jun 2017 11:24:22 +0200 Subject: [PATCH 1/2] posix: replace timex in pthread_cond --- sys/posix/pthread/pthread_cond.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sys/posix/pthread/pthread_cond.c b/sys/posix/pthread/pthread_cond.c index 8d190c152476..a51cc50c61ae 100644 --- a/sys/posix/pthread/pthread_cond.c +++ b/sys/posix/pthread/pthread_cond.c @@ -120,15 +120,12 @@ int pthread_cond_wait(pthread_cond_t *cond, mutex_t *mutex) int pthread_cond_timedwait(pthread_cond_t *cond, mutex_t *mutex, const struct timespec *abstime) { - timex_t now, then, reltime; - - xtimer_now_timex(&now); - then.seconds = abstime->tv_sec; - then.microseconds = abstime->tv_nsec / 1000u; - reltime = timex_sub(then, now); + uint64_t now = xtimer_now_usec64(); + uint64_t then = ((uint64_t)abstime->tv_sec * US_PER_SEC) + + (abstime->tv_nsec / NS_PER_US); xtimer_t timer; - xtimer_set_wakeup64(&timer, timex_uint64(reltime) , sched_active_pid); + xtimer_set_wakeup64(&timer, (then - now) , sched_active_pid); int result = pthread_cond_wait(cond, mutex); xtimer_remove(&timer); From 8253510f0bb0677bb900791f8ae4c2046f5ba926 Mon Sep 17 00:00:00 2001 From: smlng Date: Wed, 21 Jun 2017 11:35:27 +0200 Subject: [PATCH 2/2] posix: replace timex in pthread_rwlock --- sys/posix/pthread/pthread_rwlock.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/sys/posix/pthread/pthread_rwlock.c b/sys/posix/pthread/pthread_rwlock.c index dde72eb6ef40..9b345200b40a 100644 --- a/sys/posix/pthread/pthread_rwlock.c +++ b/sys/posix/pthread/pthread_rwlock.c @@ -185,22 +185,16 @@ static int pthread_rwlock_timedlock(pthread_rwlock_t *rwlock, int incr_when_held, const struct timespec *abstime) { - timex_t now, then; + uint64_t now = xtimer_now_usec64(); + uint64_t then = ((uint64_t)abstime->tv_sec * US_PER_SEC) + + (abstime->tv_nsec / NS_PER_US); - then.seconds = abstime->tv_sec; - then.microseconds = abstime->tv_nsec / 1000u; - timex_normalize(&then); - - xtimer_now_timex(&now); - - if (timex_cmp(then, now) <= 0) { + if ((then - now) <= 0) { return ETIMEDOUT; } else { - timex_t reltime = timex_sub(then, now); - xtimer_t timer; - xtimer_set_wakeup64(&timer, timex_uint64(reltime) , sched_active_pid); + xtimer_set_wakeup64(&timer, (then - now), sched_active_pid); int result = pthread_rwlock_lock(rwlock, is_blocked, is_writer, incr_when_held, true); if (result != ETIMEDOUT) { xtimer_remove(&timer);