summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <arun.raghavan@collabora.co.uk>2011-09-27 21:52:24 +0530
committerArun Raghavan <arun.raghavan@collabora.co.uk>2011-09-27 22:30:30 +0530
commit6a9272f950649fdf3650e23d08320093d6ef7a64 (patch)
treeee7e09b740bd598e8a235900ed11e7911e3173d6
parent6878140662a9de50942dfe9fc24b8139e29289cf (diff)
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.
-rw-r--r--src/pulsecore/sink.c8
-rw-r--r--src/pulsecore/source.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 21c672364..05b08aaf5 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -3400,12 +3400,12 @@ static void pa_sink_volume_change_flush(pa_sink *s) {
3400 3400
3401/* Called from the IO thread. */ 3401/* Called from the IO thread. */
3402pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) { 3402pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
3403 pa_usec_t now = pa_rtclock_now(); 3403 pa_usec_t now;
3404 pa_bool_t ret = FALSE; 3404 pa_bool_t ret = FALSE;
3405 3405
3406 pa_assert(s); 3406 pa_assert(s);
3407 3407
3408 if (!PA_SINK_IS_LINKED(s->state)) { 3408 if (!s->thread_info.volume_changes || !PA_SINK_IS_LINKED(s->state)) {
3409 if (usec_to_next) 3409 if (usec_to_next)
3410 *usec_to_next = 0; 3410 *usec_to_next = 0;
3411 return ret; 3411 return ret;
@@ -3413,6 +3413,8 @@ pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
3413 3413
3414 pa_assert(s->write_volume); 3414 pa_assert(s->write_volume);
3415 3415
3416 now = pa_rtclock_now();
3417
3416 while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) { 3418 while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) {
3417 pa_sink_volume_change *c = s->thread_info.volume_changes; 3419 pa_sink_volume_change *c = s->thread_info.volume_changes;
3418 PA_LLIST_REMOVE(pa_sink_volume_change, s->thread_info.volume_changes, c); 3420 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) {
3423 pa_sink_volume_change_free(c); 3425 pa_sink_volume_change_free(c);
3424 } 3426 }
3425 3427
3426 if (s->write_volume && ret) 3428 if (ret)
3427 s->write_volume(s); 3429 s->write_volume(s);
3428 3430
3429 if (s->thread_info.volume_changes) { 3431 if (s->thread_info.volume_changes) {
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 523961010..d47280ce8 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -2575,12 +2575,12 @@ static void pa_source_volume_change_flush(pa_source *s) {
2575 2575
2576/* Called from the IO thread. */ 2576/* Called from the IO thread. */
2577pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) { 2577pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
2578 pa_usec_t now = pa_rtclock_now(); 2578 pa_usec_t now;
2579 pa_bool_t ret = FALSE; 2579 pa_bool_t ret = FALSE;
2580 2580
2581 pa_assert(s); 2581 pa_assert(s);
2582 2582
2583 if (!PA_SOURCE_IS_LINKED(s->state)) { 2583 if (!s->thread_info.volume_changes || !PA_SOURCE_IS_LINKED(s->state)) {
2584 if (usec_to_next) 2584 if (usec_to_next)
2585 *usec_to_next = 0; 2585 *usec_to_next = 0;
2586 return ret; 2586 return ret;
@@ -2588,6 +2588,8 @@ pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
2588 2588
2589 pa_assert(s->write_volume); 2589 pa_assert(s->write_volume);
2590 2590
2591 now = pa_rtclock_now();
2592
2591 while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) { 2593 while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) {
2592 pa_source_volume_change *c = s->thread_info.volume_changes; 2594 pa_source_volume_change *c = s->thread_info.volume_changes;
2593 PA_LLIST_REMOVE(pa_source_volume_change, s->thread_info.volume_changes, c); 2595 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) {
2598 pa_source_volume_change_free(c); 2600 pa_source_volume_change_free(c);
2599 } 2601 }
2600 2602
2601 if (s->write_volume && ret) 2603 if (ret)
2602 s->write_volume(s); 2604 s->write_volume(s);
2603 2605
2604 if (s->thread_info.volume_changes) { 2606 if (s->thread_info.volume_changes) {