Skip to content

Commit

Permalink
Merge pull request RIOT-OS#7215 from smlng/posix/pthread/replace_timex
Browse files Browse the repository at this point in the history
Posix: replace all remaining usages of timex in pthread
  • Loading branch information
aabadie authored Jun 23, 2017
2 parents 02a3c9f + 8253510 commit 786baac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
11 changes: 4 additions & 7 deletions sys/posix/pthread/pthread_cond.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 5 additions & 11 deletions sys/posix/pthread/pthread_rwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 786baac

Please sign in to comment.