[pulseaudio-discuss] [PATCH RFCv3 29/51] mainloop: Annotate branches with LIKELY
Peter Meerwald
pmeerw at pmeerw.net
Tue Nov 4 15:26:24 PST 2014
From: Peter Meerwald <p.meerwald at bct-electronic.com>
Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
---
src/pulse/mainloop.c | 46 +++++++++++++++++++++++++++-------------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/src/pulse/mainloop.c b/src/pulse/mainloop.c
index a7a3c48..26320ac 100644
--- a/src/pulse/mainloop.c
+++ b/src/pulse/mainloop.c
@@ -618,7 +618,7 @@ static void rebuild_pollfds(pa_mainloop *m) {
m->n_pollfds++;
PA_LLIST_FOREACH(e, m->io_events) {
- if (e->dead) {
+ if (PA_UNLIKELY(e->dead)) {
e->pollfd = NULL;
continue;
}
@@ -659,10 +659,12 @@ static unsigned dispatch_pollfds(pa_mainloop *m) {
PA_LLIST_FOREACH(e, m->io_events) {
- if (k <= 0 || m->quit)
+ if (PA_UNLIKELY(k <= 0 || m->quit))
break;
- if (e->dead || !e->pollfd || !e->pollfd->revents)
+ if (PA_UNLIKELY(e->dead))
+ continue;
+ if (!e->pollfd || !e->pollfd->revents)
continue;
pa_assert(e->pollfd->fd == e->fd);
@@ -686,10 +688,12 @@ static unsigned dispatch_defer(pa_mainloop *m) {
PA_LLIST_FOREACH(e, m->defer_events) {
- if (m->quit)
+ if (PA_UNLIKELY(m->quit))
break;
- if (e->dead || !e->enabled)
+ if (PA_UNLIKELY(e->dead))
+ continue;
+ if (!e->enabled)
continue;
pa_assert(e->callback);
@@ -709,7 +713,9 @@ static pa_time_event* find_next_time_event(pa_mainloop *m) {
PA_LLIST_FOREACH(t, m->time_events) {
- if (t->dead || !t->enabled)
+ if (PA_UNLIKELY(t->dead))
+ continue;
+ if (!t->enabled)
continue;
if (!n || t->time < n->time) {
@@ -758,10 +764,12 @@ static unsigned dispatch_timeout(pa_mainloop *m) {
PA_LLIST_FOREACH(e, m->time_events) {
- if (m->quit)
+ if (PA_UNLIKELY(m->quit))
break;
- if (e->dead || !e->enabled)
+ if (PA_UNLIKELY(e->dead))
+ continue;
+ if (!e->enabled)
continue;
if (e->time <= now) {
@@ -795,12 +803,12 @@ int pa_mainloop_prepare(pa_mainloop *m, int timeout) {
scan_dead(m);
- if (m->quit)
+ if (PA_UNLIKELY(m->quit))
goto quit;
if (m->n_enabled_defer_events <= 0) {
- if (m->rebuild_pollfds)
+ if (PA_UNLIKELY(m->rebuild_pollfds))
rebuild_pollfds(m);
m->prepared_timeout = calc_next_timeout(m);
@@ -836,7 +844,7 @@ int pa_mainloop_poll(pa_mainloop *m) {
pa_assert(m);
pa_assert(m->state == STATE_PREPARED);
- if (m->quit)
+ if (PA_UNLIKELY(m->quit))
goto quit;
m->state = STATE_POLLING;
@@ -846,7 +854,7 @@ int pa_mainloop_poll(pa_mainloop *m) {
else {
pa_assert(!m->rebuild_pollfds);
- if (m->poll_func)
+ if (PA_UNLIKELY(m->poll_func))
m->poll_func_ret = m->poll_func(
m->pollfds, m->n_pollfds,
usec_to_timeout(m->prepared_timeout),
@@ -866,7 +874,7 @@ int pa_mainloop_poll(pa_mainloop *m) {
#endif
}
- if (m->poll_func_ret < 0) {
+ if (PA_UNLIKELY(m->poll_func_ret < 0)) {
if (errno == EINTR)
m->poll_func_ret = 0;
else
@@ -888,7 +896,7 @@ int pa_mainloop_dispatch(pa_mainloop *m) {
pa_assert(m);
pa_assert(m->state == STATE_POLLED);
- if (m->quit)
+ if (PA_UNLIKELY(m->quit))
goto quit;
if (m->n_enabled_defer_events)
@@ -897,14 +905,14 @@ int pa_mainloop_dispatch(pa_mainloop *m) {
if (m->n_enabled_time_events)
dispatched += dispatch_timeout(m);
- if (m->quit)
+ if (PA_UNLIKELY(m->quit))
goto quit;
if (m->poll_func_ret > 0)
dispatched += dispatch_pollfds(m);
}
- if (m->quit)
+ if (PA_UNLIKELY(m->quit))
goto quit;
m->state = STATE_PASSIVE;
@@ -926,13 +934,13 @@ int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval) {
int r;
pa_assert(m);
- if ((r = pa_mainloop_prepare(m, block ? -1 : 0)) < 0)
+ if (PA_UNLIKELY((r = pa_mainloop_prepare(m, block ? -1 : 0)) < 0))
goto quit;
- if ((r = pa_mainloop_poll(m)) < 0)
+ if (PA_UNLIKELY((r = pa_mainloop_poll(m)) < 0))
goto quit;
- if ((r = pa_mainloop_dispatch(m)) < 0)
+ if (PA_UNLIKELY((r = pa_mainloop_dispatch(m)) < 0))
goto quit;
return r;
--
1.9.1
More information about the pulseaudio-discuss
mailing list