[pulseaudio-discuss] [PATCH RFCv3 31/51] alsa: Annotate branches in ALSA sink/source thread_func() with LIKELY

Peter Meerwald pmeerw at pmeerw.net
Tue Nov 4 15:26:26 PST 2014


From: Peter Meerwald <p.meerwald at bct-electronic.com>

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
 src/modules/alsa/alsa-sink.c   | 22 +++++++++++-----------
 src/modules/alsa/alsa-source.c | 18 +++++++++---------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 31853c9..3d1a8ed 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1709,7 +1709,7 @@ static void thread_func(void *userdata) {
         }
 
         /* Render some data and write it to the dsp */
-        if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
+        if (PA_LIKELY(PA_SINK_IS_OPENED(u->sink->thread_info.state))) {
             int work_done;
             pa_usec_t sleep_usec = 0;
             bool on_timeout = pa_rtpoll_timer_elapsed(u->rtpoll);
@@ -1719,14 +1719,14 @@ static void thread_func(void *userdata) {
             else
                 work_done = unix_write(u, &sleep_usec, revents & POLLOUT, on_timeout);
 
-            if (work_done < 0)
+            if (PA_UNLIKELY(work_done < 0))
                 goto fail;
 
 /*             pa_log_debug("work_done = %i", work_done); */
 
-            if (work_done) {
+            if (PA_LIKELY(work_done)) {
 
-                if (u->first) {
+                if PA_UNLIKELY((u->first)) {
                     pa_log_info("Starting playback.");
                     snd_pcm_start(u->pcm_handle);
 
@@ -1741,7 +1741,7 @@ static void thread_func(void *userdata) {
             if (u->use_tsched) {
                 pa_usec_t cusec;
 
-                if (u->since_start <= u->hwbuf_size) {
+                if (PA_UNLIKELY(u->since_start <= u->hwbuf_size)) {
 
                     /* USB devices on ALSA seem to hit a buffer
                      * underrun during the first iterations much
@@ -1789,7 +1789,7 @@ static void thread_func(void *userdata) {
             }
         }
 
-        if (rtpoll_sleep > 0) {
+        if (PA_LIKELY(rtpoll_sleep > 0)) {
             pa_rtpoll_set_timer_relative(u->rtpoll, rtpoll_sleep);
 #ifdef DEBUG_TIMING
             real_sleep = pa_rtclock_now();
@@ -1799,10 +1799,10 @@ static void thread_func(void *userdata) {
             pa_rtpoll_set_timer_disabled(u->rtpoll);
 
         /* Hmm, nothing to do. Let's sleep */
-        if ((ret = pa_rtpoll_run(u->rtpoll)) < 0)
+        if (PA_UNLIKELY((ret = pa_rtpoll_run(u->rtpoll)) < 0))
             goto fail;
 
-        if (rtpoll_sleep > 0) {
+        if (PA_LIKELY(rtpoll_sleep > 0)) {
 #ifdef DEBUG_TIMING
             real_sleep = pa_rtclock_now() - real_sleep;
             pa_log_debug("Expected sleep: %0.2fms, real sleep: %0.2fms (diff %0.2f ms)",
@@ -1818,18 +1818,18 @@ static void thread_func(void *userdata) {
         if (u->sink->flags & PA_SINK_DEFERRED_VOLUME)
             pa_sink_volume_change_apply(u->sink, NULL);
 
-        if (ret == 0)
+        if (PA_UNLIKELY(ret == 0))
             goto finish;
 
         /* Tell ALSA about this and process its response */
-        if (PA_SINK_IS_OPENED(u->sink->thread_info.state)) {
+        if (PA_LIKELY(PA_SINK_IS_OPENED(u->sink->thread_info.state))) {
             struct pollfd *pollfd;
             int err;
             unsigned n;
 
             pollfd = pa_rtpoll_item_get_pollfd(u->alsa_rtpoll_item, &n);
 
-            if ((err = snd_pcm_poll_descriptors_revents(u->pcm_handle, pollfd, n, &revents)) < 0) {
+            if (PA_UNLIKELY((err = snd_pcm_poll_descriptors_revents(u->pcm_handle, pollfd, n, &revents)) < 0)) {
                 pa_log("snd_pcm_poll_descriptors_revents() failed: %s", pa_alsa_strerror(err));
                 goto fail;
             }
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 482bae7..4c7459a 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1451,7 +1451,7 @@ static void thread_func(void *userdata) {
 #endif
 
         /* Read some data and pass it to the sources */
-        if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
+        if (PA_LIKELY(PA_SOURCE_IS_OPENED(u->source->thread_info.state))) {
             int work_done;
             pa_usec_t sleep_usec = 0;
             bool on_timeout = pa_rtpoll_timer_elapsed(u->rtpoll);
@@ -1470,12 +1470,12 @@ static void thread_func(void *userdata) {
             else
                 work_done = unix_read(u, &sleep_usec, revents & POLLIN, on_timeout);
 
-            if (work_done < 0)
+            if (PA_UNLIKELY(work_done < 0))
                 goto fail;
 
 /*             pa_log_debug("work_done = %i", work_done); */
 
-            if (work_done)
+            if (PA_LIKELY(work_done))
                 update_smoother(u);
 
             if (u->use_tsched) {
@@ -1508,7 +1508,7 @@ static void thread_func(void *userdata) {
             }
         }
 
-        if (rtpoll_sleep > 0) {
+        if (PA_LIKELY(rtpoll_sleep > 0)) {
             pa_rtpoll_set_timer_relative(u->rtpoll, rtpoll_sleep);
 #ifdef DEBUG_TIMING
             real_sleep = pa_rtclock_now();
@@ -1518,10 +1518,10 @@ static void thread_func(void *userdata) {
             pa_rtpoll_set_timer_disabled(u->rtpoll);
 
         /* Hmm, nothing to do. Let's sleep */
-        if ((ret = pa_rtpoll_run(u->rtpoll)) < 0)
+        if (PA_UNLIKELY((ret = pa_rtpoll_run(u->rtpoll)) < 0))
             goto fail;
 
-        if (rtpoll_sleep > 0) {
+        if (PA_LIKELY(rtpoll_sleep > 0)) {
 #ifdef DEBUG_TIMING
             real_sleep = pa_rtclock_now() - real_sleep;
             pa_log_debug("Expected sleep: %0.2fms, real sleep: %0.2fms (diff %0.2f ms)",
@@ -1537,18 +1537,18 @@ static void thread_func(void *userdata) {
         if (u->source->flags & PA_SOURCE_DEFERRED_VOLUME)
             pa_source_volume_change_apply(u->source, NULL);
 
-        if (ret == 0)
+        if (PA_UNLIKELY(ret == 0))
             goto finish;
 
         /* Tell ALSA about this and process its response */
-        if (PA_SOURCE_IS_OPENED(u->source->thread_info.state)) {
+        if (PA_LIKELY(PA_SOURCE_IS_OPENED(u->source->thread_info.state))) {
             struct pollfd *pollfd;
             int err;
             unsigned n;
 
             pollfd = pa_rtpoll_item_get_pollfd(u->alsa_rtpoll_item, &n);
 
-            if ((err = snd_pcm_poll_descriptors_revents(u->pcm_handle, pollfd, n, &revents)) < 0) {
+            if (PA_UNLIKELY((err = snd_pcm_poll_descriptors_revents(u->pcm_handle, pollfd, n, &revents)) < 0)) {
                 pa_log("snd_pcm_poll_descriptors_revents() failed: %s", pa_alsa_strerror(err));
                 goto fail;
             }
-- 
1.9.1



More information about the pulseaudio-discuss mailing list