diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-09-18 04:08:36 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-09-18 04:14:37 +0200 |
commit | fdec460661faa802c1acf9d985990c2d1b4fa1a3 (patch) | |
tree | bc3c9f586b9216441a0f1574fded12fe9987af75 | |
parent | f7d38965b355b4932e7a17774e4625f57248f845 (diff) |
core-rtclock: introduce pa_timespec_store() akin pa_timeval_store()
-rw-r--r-- | src/pulsecore/core-rtclock.c | 14 | ||||
-rw-r--r-- | src/pulsecore/core-rtclock.h | 1 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/pulsecore/core-rtclock.c b/src/pulsecore/core-rtclock.c index 3b3e3a64..7690ab70 100644 --- a/src/pulsecore/core-rtclock.c +++ b/src/pulsecore/core-rtclock.c @@ -151,6 +151,20 @@ pa_usec_t pa_timespec_load(const struct timespec *ts) { (pa_usec_t) ts->tv_nsec / PA_NSEC_PER_USEC; } +struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v) { + pa_assert(ts); + + if (PA_UNLIKELY(v == PA_USEC_INVALID)) { + ts->tv_sec = PA_INT_TYPE_MAX(time_t); + ts->tv_nsec = (long) (PA_NSEC_PER_SEC-1); + return NULL; + } + + ts->tv_sec = (time_t) (v / PA_USEC_PER_SEC); + ts->tv_nsec = (long) ((v % PA_USEC_PER_SEC) * PA_NSEC_PER_USEC); + + return ts; +} static struct timeval* wallclock_from_rtclock(struct timeval *tv) { diff --git a/src/pulsecore/core-rtclock.h b/src/pulsecore/core-rtclock.h index 9f5ae2dd..3b393ed5 100644 --- a/src/pulsecore/core-rtclock.h +++ b/src/pulsecore/core-rtclock.h @@ -44,6 +44,7 @@ void pa_rtclock_hrtimer_enable(void); struct timeval* pa_rtclock_from_wallclock(struct timeval *tv); pa_usec_t pa_timespec_load(const struct timespec *ts); +struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v); struct timeval* pa_timeval_rtstore(struct timeval *tv, pa_usec_t v, pa_bool_t rtclock); |