sprinkly SPA_LIKELY/UNLIKELY around

This commit is contained in:
Wim Taymans 2020-03-16 12:52:28 +01:00
parent d762d57665
commit cb7bfdf98a
10 changed files with 118 additions and 129 deletions

View file

@ -502,16 +502,16 @@ static struct object *find_link(struct client *c, uint32_t src, uint32_t dst)
static struct buffer *dequeue_buffer(struct mix *mix)
{
struct buffer *b;
struct buffer *b;
if (spa_list_is_empty(&mix->queue))
return NULL;
if (SPA_UNLIKELY(spa_list_is_empty(&mix->queue)))
return NULL;
b = spa_list_first(&mix->queue, struct buffer, link);
spa_list_remove(&b->link);
b = spa_list_first(&mix->queue, struct buffer, link);
spa_list_remove(&b->link);
SPA_FLAG_SET(b->flags, BUFFER_FLAG_OUT);
return b;
return b;
}
#if defined (__SSE__)
@ -710,9 +710,8 @@ static void convert_to_midi(struct spa_pod_sequence **seq, uint32_t n_seq, void
struct spa_pod_control *c[n_seq];
uint32_t i;
for (i = 0; i < n_seq; i++) {
for (i = 0; i < n_seq; i++)
c[i] = spa_pod_control_first(&seq[i]->body);
}
while (true) {
struct spa_pod_control *next = NULL;
@ -728,7 +727,7 @@ static void convert_to_midi(struct spa_pod_sequence **seq, uint32_t n_seq, void
next_index = i;
}
}
if (next == NULL)
if (SPA_UNLIKELY(next == NULL))
break;
switch(next->type) {
@ -752,16 +751,16 @@ static void *get_buffer_output(struct client *c, struct port *p, uint32_t frames
p->io.status = -EPIPE;
p->io.buffer_id = SPA_ID_INVALID;
if ((mix = find_mix(c, p, -1)) != NULL) {
if (SPA_LIKELY((mix = find_mix(c, p, -1)) != NULL)) {
struct buffer *b;
if (mix->n_buffers == 0)
if (SPA_UNLIKELY(mix->n_buffers == 0))
goto done;
pw_log_trace(NAME" %p: port %p %d get buffer %d n_buffers:%d",
c, p, p->id, frames, mix->n_buffers);
if ((b = dequeue_buffer(mix)) == NULL) {
if (SPA_UNLIKELY((b = dequeue_buffer(mix)) == NULL)) {
pw_log_warn("port %p: out of buffers", p);
goto done;
}
@ -778,7 +777,7 @@ static void *get_buffer_output(struct client *c, struct port *p, uint32_t frames
done:
spa_list_for_each(mix, &p->mix, port_link) {
struct spa_io_buffers *mio = mix->io;
if (mio == NULL)
if (SPA_UNLIKELY(mio == NULL))
continue;
pw_log_trace(NAME" %p: port %p tee %d.%d get buffer %d io:%p",
c, p, p->id, mix->id, frames, mio);
@ -794,18 +793,18 @@ static void process_tee(struct client *c, uint32_t frames)
spa_list_for_each(p, &c->ports[SPA_DIRECTION_OUTPUT], link) {
void *ptr;
if (!p->empty_out)
if (SPA_LIKELY(!p->empty_out))
continue;
switch (p->object->port.type_id) {
case TYPE_ID_AUDIO:
ptr = get_buffer_output(c, p, frames, sizeof(float));
if (ptr != NULL)
if (SPA_LIKELY(ptr != NULL))
memcpy(ptr, p->emptyptr, frames * sizeof(float));
break;
case TYPE_ID_MIDI:
ptr = get_buffer_output(c, p, MAX_BUFFER_FRAMES, 1);
if (ptr != NULL)
if (SPA_LIKELY(ptr != NULL))
convert_from_midi(p->emptyptr, ptr, MAX_BUFFER_FRAMES * sizeof(float));
break;
default:
@ -892,10 +891,9 @@ static inline jack_transport_state_t position_to_jack(struct pw_node_activation
state = JackTransportRolling;
break;
}
if (d == NULL)
if (SPA_UNLIKELY(d == NULL))
return state;
d->unique_1++;
d->usecs = s->clock.nsec / SPA_NSEC_PER_USEC;
d->frame_rate = s->clock.rate.denom;
@ -942,7 +940,7 @@ static inline jack_transport_state_t position_to_jack(struct pw_node_activation
static inline void check_buffer_frames(struct client *c)
{
uint32_t buffer_frames = c->position->clock.duration;
if (buffer_frames != c->buffer_frames) {
if (SPA_UNLIKELY(buffer_frames != c->buffer_frames)) {
pw_log_info(NAME" %p: bufferframes %d", c, buffer_frames);
c->buffer_frames = buffer_frames;
if (c->bufsize_callback)
@ -953,7 +951,7 @@ static inline void check_buffer_frames(struct client *c)
static inline void check_sample_rate(struct client *c)
{
uint32_t sample_rate = c->position->clock.rate.denom;
if (sample_rate != c->sample_rate) {
if (SPA_UNLIKELY(sample_rate != c->sample_rate)) {
pw_log_info(NAME" %p: sample_rate %d", c, sample_rate);
c->sample_rate = sample_rate;
if (c->srate_callback)
@ -971,15 +969,15 @@ static inline uint32_t cycle_run(struct client *c)
struct pw_node_activation *driver = c->driver_activation;
/* this is blocking if nothing ready */
if (read(fd, &cmd, sizeof(cmd)) != sizeof(cmd)) {
if (SPA_UNLIKELY(read(fd, &cmd, sizeof(cmd)) != sizeof(cmd))) {
pw_log_warn(NAME" %p: read failed %m", c);
if (errno == EWOULDBLOCK)
return 0;
}
if (cmd > 1)
if (SPA_UNLIKELY(cmd > 1))
pw_log_warn(NAME" %p: missed %"PRIu64" wakeups", c, cmd - 1);
if (pos == NULL) {
if (SPA_UNLIKELY(pos == NULL)) {
pw_log_error(NAME" %p: missing position", c);
return 0;
}
@ -988,7 +986,7 @@ static inline uint32_t cycle_run(struct client *c)
activation->status = PW_NODE_ACTIVATION_AWAKE;
activation->awake_time = SPA_TIMESPEC_TO_NSEC(&ts);
if (c->first) {
if (SPA_UNLIKELY(c->first)) {
if (c->thread_init_callback)
c->thread_init_callback(c->thread_init_arg);
c->first = false;
@ -999,14 +997,14 @@ static inline uint32_t cycle_run(struct client *c)
c->jack_state = position_to_jack(driver, &c->jack_position);
if (driver) {
if (activation->pending_sync) {
if (SPA_LIKELY(driver)) {
if (SPA_UNLIKELY(activation->pending_sync)) {
if (c->sync_callback == NULL ||
c->sync_callback(c->jack_state, &c->jack_position, c->sync_arg))
activation->pending_sync = false;
}
if (c->xrun_count != driver->xrun_count &&
c->xrun_count != 0 && c->xrun_callback)
if (SPA_UNLIKELY(c->xrun_count != driver->xrun_count &&
c->xrun_count != 0 && c->xrun_callback))
c->xrun_callback(c->xrun_arg);
c->xrun_count = driver->xrun_count;
}
@ -1022,7 +1020,7 @@ static inline uint32_t cycle_wait(struct client *c)
int res;
res = pw_data_loop_wait(c->loop, -1);
if (res <= 0) {
if (SPA_UNLIKELY(res <= 0)) {
pw_log_warn(NAME" %p: wait error %m", c);
return 0;
}
@ -1047,7 +1045,7 @@ static inline void signal_sync(struct client *c)
spa_list_for_each(l, &c->target_links, target_link) {
struct pw_node_activation_state *state;
if (l->activation == NULL)
if (SPA_UNLIKELY(l->activation == NULL))
continue;
state = &l->activation->state[0];
@ -1061,7 +1059,7 @@ static inline void signal_sync(struct client *c)
pw_log_trace(NAME" %p: signal %p %p", c, l, state);
if (write(l->signalfd, &cmd, sizeof(cmd)) != sizeof(cmd))
if (SPA_UNLIKELY(write(l->signalfd, &cmd, sizeof(cmd)) != sizeof(cmd)))
pw_log_warn(NAME" %p: write failed %m", c);
}
}
@ -1072,7 +1070,7 @@ static inline void cycle_signal(struct client *c, int status)
struct pw_node_activation *driver = c->driver_activation;
struct pw_node_activation *activation = c->activation;
if (status == 0) {
if (SPA_LIKELY(status == 0)) {
if (c->timebase_callback && driver && driver->segment_owner[0] == c->node_id) {
if (activation->pending_new_pos ||
c->jack_state == JackTransportRolling ||
@ -1098,18 +1096,17 @@ on_rtsocket_condition(void *data, int fd, uint32_t mask)
{
struct client *c = data;
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
if (SPA_UNLIKELY(mask & (SPA_IO_ERR | SPA_IO_HUP))) {
pw_log_warn(NAME" %p: got error", c);
unhandle_socket(c);
return;
}
if (c->thread_callback) {
if (SPA_UNLIKELY(c->thread_callback)) {
if (!c->thread_entered) {
c->thread_entered = true;
c->thread_callback(c->thread_arg);
}
return;
} else if (mask & SPA_IO_IN) {
} else if (SPA_LIKELY(mask & SPA_IO_IN)) {
uint32_t buffer_frames;
int status;
@ -3141,7 +3138,7 @@ static inline void *get_buffer_output_float(struct client *c, struct port *p, ja
void *ptr;
ptr = get_buffer_output(c, p, frames, sizeof(float));
if (ptr == NULL) {
if (SPA_UNLIKELY(ptr == NULL)) {
p->empty_out = true;
ptr = p->emptyptr;
} else {
@ -3167,11 +3164,6 @@ void * jack_port_get_buffer (jack_port_t *port, jack_nframes_t frames)
spa_return_val_if_fail(o != NULL, NULL);
c = o->client;
if (o->type != INTERFACE_Port || o->port.port_id == SPA_ID_INVALID) {
pw_log_error(NAME" %p: invalid port %p", c, port);
return NULL;
}
p = GET_PORT(c, GET_DIRECTION(o->port.flags), o->port.port_id);
if (p->direction == SPA_DIRECTION_INPUT) {
@ -3206,7 +3198,6 @@ void * jack_port_get_buffer (jack_port_t *port, jack_nframes_t frames)
break;
}
}
pw_log_trace(NAME" %p: port %p buffer %p empty:%u", c, p, ptr, p->empty_out);
return ptr;
}
@ -4019,7 +4010,7 @@ jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *client)
spa_return_val_if_fail(c != NULL, 0);
if ((pos = c->position) == NULL)
if (SPA_UNLIKELY((pos = c->position) == NULL))
return 0;
clock_gettime(CLOCK_MONOTONIC, &ts);
@ -4043,7 +4034,7 @@ jack_nframes_t jack_last_frame_time (const jack_client_t *client)
spa_return_val_if_fail(c != NULL, 0);
if ((pos = c->position) == NULL)
if (SPA_UNLIKELY((pos = c->position) == NULL))
return 0;
return pos->clock.position;
@ -4061,7 +4052,7 @@ int jack_get_cycle_times(const jack_client_t *client,
spa_return_val_if_fail(c != NULL, -EINVAL);
if ((pos = c->position) == NULL)
if (SPA_UNLIKELY((pos = c->position) == NULL))
return -EIO;
*current_frames = pos->clock.position;
@ -4083,7 +4074,7 @@ jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t fram
spa_return_val_if_fail(c != NULL, -EINVAL);
if ((pos = c->position) == NULL)
if (SPA_UNLIKELY((pos = c->position) == NULL))
return 0;
df = (frames - pos->clock.position) * (double)SPA_NSEC_PER_SEC / c->sample_rate;
@ -4099,7 +4090,7 @@ jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t usec
spa_return_val_if_fail(c != NULL, -EINVAL);
if ((pos = c->position) == NULL)
if (SPA_UNLIKELY((pos = c->position) == NULL))
return 0;
du = (usecs - pos->clock.nsec/SPA_NSEC_PER_USEC) * (double)c->sample_rate / SPA_USEC_PER_SEC;
@ -4268,7 +4259,7 @@ jack_transport_state_t jack_transport_query (const jack_client_t *client,
spa_return_val_if_fail(c != NULL, JackTransportStopped);
if ((a = c->driver_activation) != NULL)
if (SPA_LIKELY((a = c->driver_activation) != NULL))
jack_state = position_to_jack(a, pos);
else if (pos != NULL)
memset(pos, 0, sizeof(jack_position_t));
@ -4287,7 +4278,7 @@ jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client)
spa_return_val_if_fail(c != NULL, -EINVAL);
if ((a = c->driver_activation) == NULL)
if (SPA_UNLIKELY((a = c->driver_activation) == NULL))
return -EIO;
pos = &a->position;
@ -4517,7 +4508,7 @@ void jack_set_thread_creator (jack_thread_creator_t creator)
static inline uint8_t * midi_event_data (void* port_buffer,
const struct midi_event* event)
{
if (event->size <= MIDI_INLINE_MAX)
if (SPA_LIKELY(event->size <= MIDI_INLINE_MAX))
return (uint8_t *)event->inline_data;
else
return SPA_MEMBER(port_buffer, event->byte_offset, uint8_t);
@ -4580,9 +4571,9 @@ size_t jack_midi_max_event_size(void* port_buffer)
+ ((mb->event_count + 1)
* sizeof(struct midi_event));
if (used_size > buffer_size) {
if (SPA_UNLIKELY(used_size > buffer_size)) {
return 0;
} else if ((buffer_size - used_size) < MIDI_INLINE_MAX) {
} else if (SPA_LIKELY((buffer_size - used_size) < MIDI_INLINE_MAX)) {
return MIDI_INLINE_MAX;
} else {
return buffer_size - used_size;
@ -4602,21 +4593,21 @@ jack_midi_data_t* jack_midi_event_reserve(void *port_buffer,
buffer_size = mb->buffer_size;
if (time < 0 || time >= mb->nframes) {
if (SPA_UNLIKELY(time < 0 || time >= mb->nframes)) {
pw_log_warn("midi %p: time:%d frames:%d", port_buffer, time, mb->nframes);
goto failed;
}
if (mb->event_count > 0 && time < events[mb->event_count - 1].time) {
if (SPA_UNLIKELY(mb->event_count > 0 && time < events[mb->event_count - 1].time)) {
pw_log_warn("midi %p: time:%d ev:%d", port_buffer, time, mb->event_count);
goto failed;
}
/* Check if data_size is >0 and there is enough space in the buffer for the event. */
if (data_size <= 0) {
if (SPA_UNLIKELY(data_size <= 0)) {
pw_log_warn("midi %p: data_size:%zd", port_buffer, data_size);
goto failed; // return NULL?
} else if (jack_midi_max_event_size (port_buffer) < data_size) {
} else if (SPA_UNLIKELY(jack_midi_max_event_size (port_buffer) < data_size)) {
pw_log_warn("midi %p: event too large: data_size:%zd", port_buffer, data_size);
goto failed;
} else {
@ -4625,7 +4616,7 @@ jack_midi_data_t* jack_midi_event_reserve(void *port_buffer,
ev->time = time;
ev->size = data_size;
if (data_size <= MIDI_INLINE_MAX) {
if (SPA_LIKELY(data_size <= MIDI_INLINE_MAX)) {
res = ev->inline_data;
} else {
mb->write_pos += data_size;
@ -4647,12 +4638,10 @@ int jack_midi_event_write(void *port_buffer,
size_t data_size)
{
jack_midi_data_t *retbuf = jack_midi_event_reserve (port_buffer, time, data_size);
if (retbuf) {
memcpy (retbuf, data, data_size);
return 0;
} else {
if (SPA_UNLIKELY(retbuf == NULL))
return -ENOBUFS;
}
memcpy (retbuf, data, data_size);
return 0;
}
SPA_EXPORT
@ -4674,12 +4663,12 @@ int jack_get_video_image_size(jack_client_t *client, jack_image_size_t *size)
spa_return_val_if_fail(c != NULL, 0);
a = c->driver_activation;
if (a == NULL)
if (SPA_UNLIKELY(a == NULL))
a = c->activation;
if (a == NULL)
if (SPA_UNLIKELY(a == NULL))
return -EIO;
if (!(a->position.video.flags & SPA_IO_VIDEO_SIZE_VALID))
if (SPA_UNLIKELY(!(a->position.video.flags & SPA_IO_VIDEO_SIZE_VALID)))
return -EIO;
size->width = a->position.video.size.width;

View file

@ -133,14 +133,14 @@ spa_hook_list_join(struct spa_hook_list *list,
#define spa_callbacks_call(callbacks,type,method,vers,...) \
({ \
const type *_f = (const type *) (callbacks)->funcs; \
if (_f && _f->version >= (vers) && _f->method) \
if (SPA_LIKELY(_f && _f->version >= (vers) && _f->method)) \
_f->method((callbacks)->data, ## __VA_ARGS__); \
})
#define spa_callbacks_call_res(callbacks,type,res,method,vers,...) \
({ \
const type *_f = (const type *) (callbacks)->funcs; \
if (_f && _f->version >= (vers) && _f->method) \
if (SPA_LIKELY(_f && _f->version >= (vers) && _f->method)) \
res = _f->method((callbacks)->data, ## __VA_ARGS__); \
res; \
})
@ -171,7 +171,7 @@ spa_hook_list_join(struct spa_hook_list *list,
spa_list_cursor_start(cursor, s, link); \
spa_list_for_each_cursor(ci, cursor, &list->list, link) { \
const type *_f = (const type *)ci->cb.funcs; \
if (_f && _f->version >= (vers) && _f->method) { \
if (SPA_LIKELY(_f && _f->version >= (vers) && _f->method)) { \
_f->method(ci->cb.data, ## __VA_ARGS__); \
count++; \
if (once) \

View file

@ -546,7 +546,7 @@ static int alsa_recover(struct state *state, int err)
snd_pcm_status_t *status;
snd_pcm_status_alloca(&status);
if ((res = snd_pcm_status(state->hndl, status)) < 0) {
if (SPA_UNLIKELY((res = snd_pcm_status(state->hndl, status)) < 0)) {
spa_log_error(state->log, NAME" %p: snd_pcm_status error: %s",
state, snd_strerror(res));
return res;
@ -581,7 +581,7 @@ static int alsa_recover(struct state *state, int err)
break;
}
if ((res = snd_pcm_recover(state->hndl, err, true)) < 0) {
if (SPA_UNLIKELY((res = snd_pcm_recover(state->hndl, err, true)) < 0)) {
spa_log_error(state->log, NAME" %p: snd_pcm_recover error: %s",
state, snd_strerror(res));
return res;
@ -609,7 +609,7 @@ static int get_status(struct state *state, snd_pcm_uframes_t *delay, snd_pcm_ufr
snd_pcm_sframes_t avail;
int res;
if ((avail = snd_pcm_avail(state->hndl)) < 0) {
if (SPA_UNLIKELY((avail = snd_pcm_avail(state->hndl)) < 0)) {
if ((res = alsa_recover(state, avail)) < 0)
return res;
if ((avail = snd_pcm_avail(state->hndl)) < 0) {
@ -659,7 +659,7 @@ static int update_time(struct state *state, uint64_t nsec, snd_pcm_sframes_t del
else
err = (target + 128) - delay;
if (state->bw == 0.0) {
if (SPA_UNLIKELY(state->bw == 0.0)) {
set_loop(state, BW_MAX);
state->next_time = nsec;
state->base_time = nsec;
@ -670,7 +670,7 @@ static int update_time(struct state *state, uint64_t nsec, snd_pcm_sframes_t del
corr = 1.0 - (state->z2 + state->z3);
if (state->last_threshold != state->threshold) {
if (SPA_UNLIKELY(state->last_threshold != state->threshold)) {
int32_t diff = (int32_t) (state->last_threshold - state->threshold);
spa_log_trace(state->log, NAME" %p: follower:%d quantum change %d",
state, follower, diff);
@ -678,7 +678,7 @@ static int update_time(struct state *state, uint64_t nsec, snd_pcm_sframes_t del
state->last_threshold = state->threshold;
}
if ((state->next_time - state->base_time) > BW_PERIOD) {
if (SPA_UNLIKELY((state->next_time - state->base_time) > BW_PERIOD)) {
state->base_time = state->next_time;
if (state->bw == BW_MAX)
set_loop(state, BW_MED);
@ -701,7 +701,7 @@ static int update_time(struct state *state, uint64_t nsec, snd_pcm_sframes_t del
state->next_time += state->threshold / corr * 1e9 / state->rate;
if (!follower && state->clock) {
if (SPA_LIKELY(!follower && state->clock)) {
state->clock->nsec = nsec;
state->clock->position += state->duration;
state->clock->duration = state->duration;
@ -724,7 +724,7 @@ int spa_alsa_write(struct state *state, snd_pcm_uframes_t silence)
snd_pcm_uframes_t written, frames, offset, off, to_write, total_written;
int res;
if (state->position && state->duration != state->position->clock.duration) {
if (SPA_LIKELY(state->position && state->duration != state->position->clock.duration)) {
state->duration = state->position->clock.duration;
state->threshold = (state->duration * state->rate + state->rate_denom-1) / state->rate_denom;
}
@ -733,16 +733,16 @@ int spa_alsa_write(struct state *state, snd_pcm_uframes_t silence)
uint64_t nsec;
snd_pcm_uframes_t delay, target;
if ((res = get_status(state, &delay, &target)) < 0)
if (SPA_UNLIKELY((res = get_status(state, &delay, &target)) < 0))
return res;
if (!state->alsa_recovering && delay > target + state->threshold) {
if (SPA_UNLIKELY(!state->alsa_recovering && delay > target + state->threshold)) {
spa_log_warn(state->log, NAME" %p: follower delay:%ld resync %f %f %f",
state, delay, state->z1, state->z2, state->z3);
init_loop(state);
state->alsa_sync = true;
}
if (state->alsa_sync) {
if (SPA_UNLIKELY(state->alsa_sync)) {
if (delay > target)
snd_pcm_rewind(state->hndl, delay - target);
else
@ -753,14 +753,14 @@ int spa_alsa_write(struct state *state, snd_pcm_uframes_t silence)
}
nsec = state->position->clock.nsec;
if ((res = update_time(state, nsec, delay, target, true)) < 0)
if (SPA_UNLIKELY((res = update_time(state, nsec, delay, target, true)) < 0))
return res;
}
total_written = 0;
again:
frames = state->buffer_frames;
if ((res = snd_pcm_mmap_begin(hndl, &my_areas, &offset, &frames)) < 0) {
if (SPA_UNLIKELY((res = snd_pcm_mmap_begin(hndl, &my_areas, &offset, &frames)) < 0)) {
spa_log_error(state->log, NAME" %p: snd_pcm_mmap_begin error: %s",
state, snd_strerror(res));
return res;
@ -801,7 +801,7 @@ again:
l1 = n_bytes - l0;
spa_memcpy(dst, src + offs, l0);
if (l1 > 0)
if (SPA_UNLIKELY(l1 > 0))
spa_memcpy(dst + l0, src, l1);
state->ready_offset += n_bytes;
@ -825,7 +825,7 @@ again:
silence = 0;
}
if (silence > 0) {
if (SPA_UNLIKELY(silence > 0)) {
spa_log_trace_fp(state->log, NAME" %p: silence %ld", state, silence);
snd_pcm_areas_silence(my_areas, off, state->channels, silence, state->format);
written += silence;
@ -835,7 +835,7 @@ again:
state, offset, written, state->sample_count);
total_written += written;
if ((res = snd_pcm_mmap_commit(hndl, offset, written)) < 0) {
if (SPA_UNLIKELY((res = snd_pcm_mmap_commit(hndl, offset, written)) < 0)) {
spa_log_error(state->log, NAME" %p: snd_pcm_mmap_commit error: %s",
state, snd_strerror(res));
if (res != -EPIPE && res != -ESTRPIPE)
@ -847,7 +847,7 @@ again:
state->sample_count += total_written;
if (!state->alsa_started && total_written > 0) {
if (SPA_UNLIKELY(!state->alsa_started && total_written > 0)) {
spa_log_trace(state->log, NAME" %p: snd_pcm_start %lu", state, written);
if ((res = snd_pcm_start(hndl)) < 0) {
spa_log_error(state->log, NAME" %p: snd_pcm_start: %s",
@ -1012,13 +1012,13 @@ static int handle_play(struct state *state, uint64_t nsec,
{
int res;
if (delay > target + state->last_threshold) {
if (SPA_UNLIKELY(delay > target + state->last_threshold)) {
spa_log_trace(state->log, NAME" %p: early wakeup %ld %ld", state, delay, target);
state->next_time = nsec + (delay - target) * SPA_NSEC_PER_SEC / state->rate;
return -EAGAIN;
}
if ((res = update_time(state, nsec, delay, target, false)) < 0)
if (SPA_UNLIKELY((res = update_time(state, nsec, delay, target, false)) < 0))
return res;
if (spa_list_is_empty(&state->ready)) {
@ -1076,15 +1076,15 @@ static void alsa_on_timeout_event(struct spa_source *source)
uint64_t expire;
int res;
if (state->started && spa_system_timerfd_read(state->data_system, state->timerfd, &expire) < 0)
if (SPA_UNLIKELY(state->started && spa_system_timerfd_read(state->data_system, state->timerfd, &expire) < 0))
spa_log_warn(state->log, NAME" %p: error reading timerfd: %m", state);
if (state->position) {
if (SPA_LIKELY(state->position)) {
state->duration = state->position->clock.duration;
state->threshold = (state->duration * state->rate + state->rate_denom-1) / state->rate_denom;
}
if ((res = get_status(state, &delay, &target)) < 0)
if (SPA_UNLIKELY((res = get_status(state, &delay, &target)) < 0))
return;
state->current_time = state->next_time;

View file

@ -1074,15 +1074,15 @@ static int impl_node_process(void *object)
r = spa_node_process(this->nodes[i]);
spa_log_trace_fp(this->log, NAME " %p: process %d %d: %s",
this, i, r, r < 0 ? spa_strerror(r) : "ok");
if (r < 0)
if (SPA_UNLIKELY(r < 0))
return r;
if (r & SPA_STATUS_HAVE_DATA)
ready++;
if (i == 0)
if (SPA_UNLIKELY(i == 0))
res |= r & SPA_STATUS_NEED_DATA;
if (i == this->n_nodes-1)
if (SPA_UNLIKELY(i == this->n_nodes-1))
res |= r & SPA_STATUS_HAVE_DATA;
}
if (res & SPA_STATUS_HAVE_DATA)

View file

@ -37,7 +37,7 @@ conv_s16_to_f32d_1s_sse2(void *data, void * SPA_RESTRICT dst[], const void * SPA
__m128i in;
__m128 out, factor = _mm_set1_ps(1.0f / S16_SCALE);
if (SPA_IS_ALIGNED(d0, 16))
if (SPA_LIKELY(SPA_IS_ALIGNED(d0, 16)))
unrolled = n_samples & ~3;
else
unrolled = 0;

View file

@ -37,8 +37,8 @@ static inline void mix_2(float * dst, const float * SPA_RESTRICT src, uint32_t n
uint32_t n, unrolled;
__m128 in1[4], in2[4];
if (SPA_IS_ALIGNED(src, 16) &&
SPA_IS_ALIGNED(dst, 16))
if (SPA_LIKELY(SPA_IS_ALIGNED(src, 16) &&
SPA_IS_ALIGNED(dst, 16)))
unrolled = n_samples & ~15;
else
unrolled = 0;

View file

@ -666,11 +666,11 @@ static int impl_node_process(void *object)
spa_log_trace_fp(this->log, NAME " %p: status %p %d %d",
this, outio, outio->status, outio->buffer_id);
if (outio->status == SPA_STATUS_HAVE_DATA)
if (SPA_UNLIKELY(outio->status == SPA_STATUS_HAVE_DATA))
return outio->status;
/* recycle */
if (outio->buffer_id < outport->n_buffers) {
if (SPA_LIKELY(outio->buffer_id < outport->n_buffers)) {
queue_buffer(this, outport, &outport->buffers[outio->buffer_id]);
outio->buffer_id = SPA_ID_INVALID;
}
@ -686,10 +686,10 @@ static int impl_node_process(void *object)
struct spa_io_buffers *inio = NULL;
struct buffer *inb;
if (!inport->valid ||
if (SPA_UNLIKELY(!inport->valid ||
(inio = inport->io) == NULL ||
inio->buffer_id >= inport->n_buffers ||
inio->status != SPA_STATUS_HAVE_DATA) {
inio->status != SPA_STATUS_HAVE_DATA)) {
spa_log_trace_fp(this->log, NAME " %p: skip input idx:%d valid:%d "
"io:%p status:%d buf_id:%d n_buffers:%d", this,
i, inport->valid, inio,
@ -711,7 +711,7 @@ static int impl_node_process(void *object)
}
outb = dequeue_buffer(this, outport);
if (outb == NULL) {
if (SPA_UNLIKELY(outb == NULL)) {
spa_log_trace(this->log, NAME " %p: out of buffers", this);
return -EPIPE;
}

View file

@ -297,10 +297,11 @@ static int loop_iterate(void *object, int timeout)
}
for (i = 0; i < nfds; i++) {
struct spa_source *s = ep[i].data;
if (s->rmask && s->fd != -1 && s->loop == loop)
if (SPA_LIKELY(s->rmask && s->fd != -1 && s->loop == loop))
s->func(s);
}
process_destroy(impl);
if (SPA_UNLIKELY(!spa_list_is_empty(&impl->destroy_list)))
process_destroy(impl);
return nfds;
}
@ -478,7 +479,7 @@ static int loop_signal_event(void *object, struct spa_source *source)
struct source_impl *impl = SPA_CONTAINER_OF(source, struct source_impl, source);
int res;
if ((res = spa_system_eventfd_write(impl->impl->system, source->fd, 1)) < 0)
if (SPA_UNLIKELY((res = spa_system_eventfd_write(impl->impl->system, source->fd, 1)) < 0))
spa_log_warn(impl->impl->log, NAME " %p: failed to write event fd %d: %s",
source, source->fd, spa_strerror(res));
return res;
@ -490,8 +491,8 @@ static void source_timer_func(struct spa_source *source)
uint64_t expirations;
int res;
if ((res = spa_system_timerfd_read(impl->impl->system,
source->fd, &expirations)) < 0)
if (SPA_UNLIKELY((res = spa_system_timerfd_read(impl->impl->system,
source->fd, &expirations)) < 0))
spa_log_warn(impl->impl->log, NAME " %p: failed to read timer fd %d: %s",
source, source->fd, spa_strerror(res));
@ -547,18 +548,18 @@ loop_update_timer(void *object, struct spa_source *source,
int flags = 0, res;
spa_zero(its);
if (value) {
if (SPA_LIKELY(value)) {
its.it_value = *value;
} else if (interval) {
its.it_value = *interval;
absolute = true;
}
if (interval)
if (SPA_UNLIKELY(interval))
its.it_interval = *interval;
if (absolute)
if (SPA_LIKELY(absolute))
flags |= SPA_FD_TIMER_ABSTIME;
if ((res = spa_system_timerfd_settime(impl->system, source->fd, flags, &its, NULL)) < 0)
if (SPA_UNLIKELY((res = spa_system_timerfd_settime(impl->system, source->fd, flags, &its, NULL)) < 0))
return res;
return 0;

View file

@ -814,7 +814,7 @@ static inline int resume_node(struct pw_impl_node *this, int status)
static inline void calculate_stats(struct pw_impl_node *this, struct pw_node_activation *a)
{
if (a->signal_time > a->prev_signal_time) {
if (SPA_LIKELY(a->signal_time > a->prev_signal_time)) {
uint64_t process_time = a->finish_time - a->signal_time;
uint64_t period_time = a->signal_time - a->prev_signal_time;
float load = (float) process_time / (float) period_time;
@ -854,7 +854,7 @@ static inline int process_node(void *data)
spa_node_process(p->mix);
}
if (this == this->driver_node && !this->exported) {
if (SPA_UNLIKELY(this == this->driver_node && !this->exported)) {
spa_system_clock_gettime(data_system, CLOCK_MONOTONIC, &ts);
a->status = PW_NODE_ACTIVATION_FINISHED;
a->signal_time = a->finish_time;
@ -886,15 +886,15 @@ static void node_on_fd_events(struct spa_source *source)
struct pw_impl_node *this = source->data;
struct spa_system *data_system = this->context->data_system;
if (source->rmask & (SPA_IO_ERR | SPA_IO_HUP)) {
if (SPA_UNLIKELY(source->rmask & (SPA_IO_ERR | SPA_IO_HUP))) {
pw_log_warn(NAME" %p: got socket error %08x", this, source->rmask);
return;
}
if (source->rmask & SPA_IO_IN) {
if (SPA_LIKELY(source->rmask & SPA_IO_IN)) {
uint64_t cmd;
if (spa_system_eventfd_read(data_system, this->source.fd, &cmd) < 0 || cmd != 1)
if (SPA_UNLIKELY(spa_system_eventfd_read(data_system, this->source.fd, &cmd) < 0 || cmd != 1))
pw_log_warn(NAME" %p: read %"PRIu64" failed %m", this, cmd);
pw_log_trace_fp(NAME" %p: got process", this);
@ -1222,13 +1222,13 @@ static int check_updates(struct pw_impl_node *node, uint32_t *reposition_owner)
struct pw_node_activation *a = node->rt.activation;
uint32_t command;
if (a->position.offset == INT64_MIN)
if (SPA_UNLIKELY(a->position.offset == INT64_MIN))
a->position.offset = a->position.clock.position;
command = ATOMIC_XCHG(a->command, PW_NODE_ACTIVATION_COMMAND_NONE);
*reposition_owner = ATOMIC_XCHG(a->reposition_owner, 0);
if (command != PW_NODE_ACTIVATION_COMMAND_NONE) {
if (SPA_UNLIKELY(command != PW_NODE_ACTIVATION_COMMAND_NONE)) {
pw_log_debug(NAME" %p: update command:%u", node, command);
switch (command) {
case PW_NODE_ACTIVATION_COMMAND_STOP:
@ -1309,13 +1309,13 @@ static int node_ready(void *data, int status)
pw_log_trace_fp(NAME" %p: ready driver:%d exported:%d %p status:%d", node,
node->driver, node->exported, driver, status);
if (node == driver) {
if (SPA_UNLIKELY(node == driver)) {
struct pw_node_activation *a = node->rt.activation;
int sync_type, all_ready, update_sync, target_sync;
uint32_t owner[2], reposition_owner;
uint64_t min_timeout = UINT64_MAX;
if (a->state[0].pending > 0) {
if (SPA_UNLIKELY(a->state[0].pending > 0)) {
pw_log_warn(NAME" %p: graph not finished: pending %d", node, a->state[0].pending);
pw_context_driver_emit_incomplete(node->context, node);
dump_states(node);
@ -1335,23 +1335,23 @@ static int node_ready(void *data, int status)
ta->status = PW_NODE_ACTIVATION_NOT_TRIGGERED;
pw_node_activation_state_reset(&ta->state[0]);
if (t->node) {
if (SPA_LIKELY(t->node)) {
uint32_t id = t->node->info.id;
/* this is the node with reposition info */
if (id == reposition_owner)
if (SPA_UNLIKELY(id == reposition_owner))
reposition_node = t->node;
/* update extra segment info if it is the owner */
if (id == owner[0])
if (SPA_UNLIKELY(id == owner[0]))
a->position.segments[0].bar = ta->segment.bar;
if (id == owner[1])
if (SPA_UNLIKELY(id == owner[1]))
a->position.segments[0].video = ta->segment.video;
min_timeout = SPA_MIN(min_timeout, ta->sync_timeout);
}
if (update_sync) {
if (SPA_UNLIKELY(update_sync)) {
ta->pending_sync = target_sync;
ta->pending_new_pos = target_sync;
} else {
@ -1361,19 +1361,18 @@ static int node_ready(void *data, int status)
a->prev_signal_time = a->signal_time;
a->sync_timeout = SPA_MIN(min_timeout, DEFAULT_SYNC_TIMEOUT);
if (reposition_node)
if (SPA_UNLIKELY(reposition_node))
do_reposition(node, reposition_node);
update_position(node, all_ready);
}
if (node->driver && !node->master)
if (SPA_UNLIKELY(node->driver && !node->master))
return 0;
if (status & SPA_STATUS_HAVE_DATA) {
spa_list_for_each(p, &node->rt.output_mix, rt.node_link)
spa_node_process(p->mix);
}
return resume_node(node, status);
}

View file

@ -153,7 +153,7 @@ static int schedule_mix_input(void *object)
struct spa_io_buffers *io = &this->rt.io;
struct pw_impl_port_mix *mix;
if (PW_IMPL_PORT_IS_CONTROL(this))
if (SPA_UNLIKELY(PW_IMPL_PORT_IS_CONTROL(this)))
return SPA_STATUS_HAVE_DATA | SPA_STATUS_NEED_DATA;
spa_list_for_each(mix, &this->rt.mix_list, rt_link) {