mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
Fix pa_rtclock_from_wallclock
The HAVE_CLOCK_GETTIME macro protects timespec and related functions, nothing of which is used in pa_rtclock_from_wallclock. And silently just not converting was not the proper solution anyway. Also add an assert in pulse/mainloop.c to report the integer overflow that was triggered by the wrong pa_rtclock_from_wallclock. Without the assert, debugging was painful.
This commit is contained in:
parent
c470680e1b
commit
b599d3c836
2 changed files with 18 additions and 19 deletions
|
|
@ -151,7 +151,7 @@ static pa_io_event_flags_t map_flags_from_libc(short flags) {
|
|||
|
||||
/* IO events */
|
||||
static pa_io_event* mainloop_io_new(
|
||||
pa_mainloop_api*a,
|
||||
pa_mainloop_api *a,
|
||||
int fd,
|
||||
pa_io_event_flags_t events,
|
||||
pa_io_event_cb_t callback,
|
||||
|
|
@ -244,7 +244,7 @@ static void mainloop_io_set_destroy(pa_io_event *e, pa_io_event_destroy_cb_t cal
|
|||
|
||||
/* Defer events */
|
||||
static pa_defer_event* mainloop_defer_new(
|
||||
pa_mainloop_api*a,
|
||||
pa_mainloop_api *a,
|
||||
pa_defer_event_cb_t callback,
|
||||
void *userdata) {
|
||||
|
||||
|
|
@ -331,7 +331,7 @@ static pa_usec_t make_rt(const struct timeval *tv, pa_bool_t *use_rtclock) {
|
|||
}
|
||||
|
||||
static pa_time_event* mainloop_time_new(
|
||||
pa_mainloop_api*a,
|
||||
pa_mainloop_api *a,
|
||||
const struct timeval *tv,
|
||||
pa_time_event_cb_t callback,
|
||||
void *userdata) {
|
||||
|
|
@ -355,7 +355,7 @@ static pa_time_event* mainloop_time_new(
|
|||
|
||||
if ((e->enabled = (t != PA_USEC_INVALID))) {
|
||||
e->time = t;
|
||||
e->use_rtclock= use_rtclock;
|
||||
e->use_rtclock = use_rtclock;
|
||||
|
||||
m->n_enabled_time_events++;
|
||||
|
||||
|
|
@ -438,7 +438,7 @@ static void mainloop_time_set_destroy(pa_time_event *e, pa_time_event_destroy_cb
|
|||
|
||||
/* quit() */
|
||||
|
||||
static void mainloop_quit(pa_mainloop_api*a, int retval) {
|
||||
static void mainloop_quit(pa_mainloop_api *a, int retval) {
|
||||
pa_mainloop *m;
|
||||
|
||||
pa_assert(a);
|
||||
|
|
@ -591,7 +591,7 @@ static void cleanup_defer_events(pa_mainloop *m, pa_bool_t force) {
|
|||
}
|
||||
|
||||
|
||||
void pa_mainloop_free(pa_mainloop* m) {
|
||||
void pa_mainloop_free(pa_mainloop *m) {
|
||||
pa_assert(m);
|
||||
|
||||
cleanup_io_events(m, TRUE);
|
||||
|
|
@ -848,10 +848,15 @@ quit:
|
|||
}
|
||||
|
||||
static int usec_to_timeout(pa_usec_t u) {
|
||||
int timeout;
|
||||
|
||||
if (u == PA_USEC_INVALID)
|
||||
return -1;
|
||||
|
||||
return (u + PA_USEC_PER_MSEC - 1) / PA_USEC_PER_MSEC;
|
||||
timeout = (u + PA_USEC_PER_MSEC - 1) / PA_USEC_PER_MSEC;
|
||||
pa_assert(timeout >= 0);
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
int pa_mainloop_poll(pa_mainloop *m) {
|
||||
|
|
@ -988,7 +993,7 @@ void pa_mainloop_quit(pa_mainloop *m, int retval) {
|
|||
pa_mainloop_wakeup(m);
|
||||
}
|
||||
|
||||
pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m) {
|
||||
pa_mainloop_api* pa_mainloop_get_api(pa_mainloop *m) {
|
||||
pa_assert(m);
|
||||
|
||||
return &m->api;
|
||||
|
|
@ -1001,7 +1006,7 @@ void pa_mainloop_set_poll_func(pa_mainloop *m, pa_poll_func poll_func, void *use
|
|||
m->poll_func_userdata = userdata;
|
||||
}
|
||||
|
||||
pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api*m) {
|
||||
pa_bool_t pa_mainloop_is_our_api(pa_mainloop_api *m) {
|
||||
pa_assert(m);
|
||||
|
||||
return m->io_new == mainloop_io_new;
|
||||
|
|
|
|||
|
|
@ -182,15 +182,13 @@ void pa_rtclock_hrtimer_enable(void) {
|
|||
}
|
||||
|
||||
struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) {
|
||||
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
struct timeval wc_now, rt_now;
|
||||
|
||||
pa_assert(tv);
|
||||
|
||||
pa_gettimeofday(&wc_now);
|
||||
pa_rtclock_get(&rt_now);
|
||||
|
||||
pa_assert(tv);
|
||||
|
||||
/* pa_timeval_sub() saturates on underflow! */
|
||||
|
||||
if (pa_timeval_cmp(&wc_now, tv) < 0)
|
||||
|
|
@ -199,7 +197,6 @@ struct timeval* pa_rtclock_from_wallclock(struct timeval *tv) {
|
|||
pa_timeval_sub(&rt_now, pa_timeval_diff(&wc_now, tv));
|
||||
|
||||
*tv = rt_now;
|
||||
#endif
|
||||
|
||||
return tv;
|
||||
}
|
||||
|
|
@ -232,15 +229,13 @@ struct timespec* pa_timespec_store(struct timespec *ts, pa_usec_t v) {
|
|||
#endif
|
||||
|
||||
static struct timeval* wallclock_from_rtclock(struct timeval *tv) {
|
||||
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
struct timeval wc_now, rt_now;
|
||||
|
||||
pa_assert(tv);
|
||||
|
||||
pa_gettimeofday(&wc_now);
|
||||
pa_rtclock_get(&rt_now);
|
||||
|
||||
pa_assert(tv);
|
||||
|
||||
/* pa_timeval_sub() saturates on underflow! */
|
||||
|
||||
if (pa_timeval_cmp(&rt_now, tv) < 0)
|
||||
|
|
@ -249,7 +244,6 @@ static struct timeval* wallclock_from_rtclock(struct timeval *tv) {
|
|||
pa_timeval_sub(&wc_now, pa_timeval_diff(&rt_now, tv));
|
||||
|
||||
*tv = wc_now;
|
||||
#endif
|
||||
|
||||
return tv;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue