sink,source: Avoid unnecessary call to pa_rtclock_now()

pa_{sink,source}_volume_change_apply were being called by the ALSA I/O
thread on every iteration, causing a pa_rtclock_now() call, which can
sometimes be heavy. We avoid this call by making sure there actually are
changes to apply before proceeding into the function.

While we're at it, also dropping a redundant check on s->write_volume.
This commit is contained in:
Arun Raghavan 2011-09-27 21:52:24 +05:30
parent 6878140662
commit 6a9272f950
2 changed files with 10 additions and 6 deletions

View file

@ -3400,12 +3400,12 @@ static void pa_sink_volume_change_flush(pa_sink *s) {
/* Called from the IO thread. */
pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
pa_usec_t now = pa_rtclock_now();
pa_usec_t now;
pa_bool_t ret = FALSE;
pa_assert(s);
if (!PA_SINK_IS_LINKED(s->state)) {
if (!s->thread_info.volume_changes || !PA_SINK_IS_LINKED(s->state)) {
if (usec_to_next)
*usec_to_next = 0;
return ret;
@ -3413,6 +3413,8 @@ pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
pa_assert(s->write_volume);
now = pa_rtclock_now();
while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) {
pa_sink_volume_change *c = s->thread_info.volume_changes;
PA_LLIST_REMOVE(pa_sink_volume_change, s->thread_info.volume_changes, c);
@ -3423,7 +3425,7 @@ pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
pa_sink_volume_change_free(c);
}
if (s->write_volume && ret)
if (ret)
s->write_volume(s);
if (s->thread_info.volume_changes) {

View file

@ -2575,12 +2575,12 @@ static void pa_source_volume_change_flush(pa_source *s) {
/* Called from the IO thread. */
pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
pa_usec_t now = pa_rtclock_now();
pa_usec_t now;
pa_bool_t ret = FALSE;
pa_assert(s);
if (!PA_SOURCE_IS_LINKED(s->state)) {
if (!s->thread_info.volume_changes || !PA_SOURCE_IS_LINKED(s->state)) {
if (usec_to_next)
*usec_to_next = 0;
return ret;
@ -2588,6 +2588,8 @@ pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
pa_assert(s->write_volume);
now = pa_rtclock_now();
while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) {
pa_source_volume_change *c = s->thread_info.volume_changes;
PA_LLIST_REMOVE(pa_source_volume_change, s->thread_info.volume_changes, c);
@ -2598,7 +2600,7 @@ pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
pa_source_volume_change_free(c);
}
if (s->write_volume && ret)
if (ret)
s->write_volume(s);
if (s->thread_info.volume_changes) {