diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-09-18 04:11:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-09-18 04:14:39 +0200 |
commit | c024aeaae91c139914dc928df975ea311729052c (patch) | |
tree | be706c14d4cb32782ff44681afec066b895758da | |
parent | a1da83b206d4a73bfa537ab3694bac7244bd19a1 (diff) |
timeval: make timeval conversion routines handle PA_USEC_INVALID special
-rw-r--r-- | src/pulse/timeval.c | 11 | ||||
-rw-r--r-- | src/pulsecore/core-rtclock.c | 8 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/pulse/timeval.c b/src/pulse/timeval.c index 87569cf1..cde4417c 100644 --- a/src/pulse/timeval.c +++ b/src/pulse/timeval.c @@ -193,6 +193,13 @@ underflow: struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v) { pa_assert(tv); + if (PA_UNLIKELY(v == PA_USEC_INVALID)) { + tv->tv_sec = PA_INT_TYPE_MAX(time_t); + tv->tv_usec = (suseconds_t) (PA_USEC_PER_SEC-1); + + return tv; + } + tv->tv_sec = (time_t) (v / PA_USEC_PER_SEC); tv->tv_usec = (suseconds_t) (v % PA_USEC_PER_SEC); @@ -200,7 +207,9 @@ struct timeval* pa_timeval_store(struct timeval *tv, pa_usec_t v) { } pa_usec_t pa_timeval_load(const struct timeval *tv) { - pa_assert(tv); + + if (PA_UNLIKELY(!tv)) + return PA_USEC_INVALID; return (pa_usec_t) tv->tv_sec * PA_USEC_PER_SEC + diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c index 7690ab70..1420470a 100644 --- a/src/pulsecore/core-rtclock.c +++ b/src/pulsecore/core-rtclock.c @@ -132,6 +132,8 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) { pa_assert(tv); + /* pa_timeval_sub() saturates on underflow! */ + if (pa_timeval_cmp(&wc_now, tv) < 0) pa_timeval_add(&rt_now, pa_timeval_diff(tv, &wc_now)); else @@ -144,7 +146,9 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) { } pa_usec_t pa_timespec_load(const struct timespec *ts) { - pa_assert(ts); + + if (PA_UNLIKELY(!ts)) + return PA_USEC_INVALID; return (pa_usec_t) ts->tv_sec * PA_USEC_PER_SEC + @@ -176,6 +180,8 @@ static struct timeval* wallclock_from_rtclock(struct timeval *tv) { pa_assert(tv); + /* pa_timeval_sub() saturates on underflow! */ + if (pa_timeval_cmp(&rt_now, tv) < 0) pa_timeval_add(&wc_now, pa_timeval_diff(tv, &rt_now)); else |