diff options
-rw-r--r-- | src/pulsecore/rtclock.c | 21 | ||||
-rw-r--r-- | src/pulsecore/rtclock.h | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/pulsecore/rtclock.c b/src/pulsecore/rtclock.c index 07d776e4..e74e5243 100644 --- a/src/pulsecore/rtclock.c +++ b/src/pulsecore/rtclock.c @@ -96,3 +96,24 @@ pa_usec_t pa_rtclock_usec(void) { return pa_timeval_load(pa_rtclock_get(&tv)); } + +struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) { + +#ifdef HAVE_CLOCK_GETTIME + struct timeval wc_now, rt_now; + + pa_gettimeofday(&wc_now); + pa_rtclock_get(&rt_now); + + pa_assert(tv); + + if (pa_timeval_cmp(&wc_now, tv) < 0) + pa_timeval_add(&rt_now, pa_timeval_diff(tv, &wc_now)); + else + pa_timeval_sub(&rt_now, pa_timeval_diff(&wc_now, tv)); + + *tv = rt_now; +#endif + + return tv; +} diff --git a/src/pulsecore/rtclock.h b/src/pulsecore/rtclock.h index f0360af3..f68ad761 100644 --- a/src/pulsecore/rtclock.h +++ b/src/pulsecore/rtclock.h @@ -40,4 +40,6 @@ pa_bool_t pa_rtclock_hrtimer(void); /* timer with a resolution better than this are considered high-resolution */ #define PA_HRTIMER_THRESHOLD_USEC 10 +struct timeval* pa_rtclock_from_wallclock(struct timeval *tv); + #endif |