mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -05:00
ringbuffer: use gcc atomic operations
Remove barrier, use GCC atomic operations for ringbuffer
This commit is contained in:
parent
02d4dc0efd
commit
baada0a330
7 changed files with 32 additions and 92 deletions
|
|
@ -189,9 +189,9 @@ loop_invoke (SpaLoop *loop,
|
|||
res = func (loop, false, seq, size, data, user_data);
|
||||
} else {
|
||||
int32_t filled, avail;
|
||||
uint32_t offset, l0;
|
||||
uint32_t idx, offset, l0;
|
||||
|
||||
filled = spa_ringbuffer_get_write_index (&impl->buffer, &offset);
|
||||
filled = spa_ringbuffer_get_write_index (&impl->buffer, &idx);
|
||||
if (filled < 0 || filled > impl->buffer.size) {
|
||||
pinos_log_warn ("data-loop %p: queue xrun %d", impl, filled);
|
||||
return SPA_RESULT_ERROR;
|
||||
|
|
@ -201,7 +201,7 @@ loop_invoke (SpaLoop *loop,
|
|||
pinos_log_warn ("data-loop %p: queue full %d", impl, avail);
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
offset &= impl->buffer.mask;
|
||||
offset = idx & impl->buffer.mask;
|
||||
|
||||
l0 = offset + avail;
|
||||
if (l0 > impl->buffer.size)
|
||||
|
|
@ -224,7 +224,7 @@ loop_invoke (SpaLoop *loop,
|
|||
}
|
||||
memcpy (item->data, data, size);
|
||||
|
||||
spa_ringbuffer_write_advance (&impl->buffer, item->item_size);
|
||||
spa_ringbuffer_write_update (&impl->buffer, idx + item->item_size);
|
||||
|
||||
pinos_loop_signal_event (&impl->this, impl->event);
|
||||
|
||||
|
|
@ -242,12 +242,12 @@ event_func (SpaLoopUtils *utils,
|
|||
void *data)
|
||||
{
|
||||
PinosLoopImpl *impl = data;
|
||||
uint32_t offset;
|
||||
uint32_t index;
|
||||
|
||||
while (spa_ringbuffer_get_read_index (&impl->buffer, &offset) > 0) {
|
||||
InvokeItem *item = SPA_MEMBER (impl->buffer_data, offset & impl->buffer.mask, InvokeItem);
|
||||
while (spa_ringbuffer_get_read_index (&impl->buffer, &index) > 0) {
|
||||
InvokeItem *item = SPA_MEMBER (impl->buffer_data, index & impl->buffer.mask, InvokeItem);
|
||||
item->func (impl->this.loop, true, item->seq, item->size, item->data, item->user_data);
|
||||
spa_ringbuffer_read_advance (&impl->buffer, item->item_size);
|
||||
spa_ringbuffer_read_update (&impl->buffer, index + item->item_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ typedef struct {
|
|||
size_t offset;
|
||||
|
||||
SpaEvent current;
|
||||
uint32_t current_offset;
|
||||
uint32_t current_index;
|
||||
} PinosTransportImpl;
|
||||
|
||||
static size_t
|
||||
|
|
@ -223,7 +223,7 @@ pinos_transport_add_event (PinosTransport *trans,
|
|||
index & trans->output_buffer->mask,
|
||||
event,
|
||||
size);
|
||||
spa_ringbuffer_write_advance (trans->output_buffer, size);
|
||||
spa_ringbuffer_write_update (trans->output_buffer, index + size);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
@ -234,20 +234,17 @@ pinos_transport_next_event (PinosTransport *trans,
|
|||
{
|
||||
PinosTransportImpl *impl = (PinosTransportImpl *) trans;
|
||||
int32_t avail;
|
||||
uint32_t index;
|
||||
|
||||
if (impl == NULL || event == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
avail = spa_ringbuffer_get_read_index (trans->input_buffer, &index);
|
||||
avail = spa_ringbuffer_get_read_index (trans->input_buffer, &impl->current_index);
|
||||
if (avail < sizeof (SpaEvent))
|
||||
return SPA_RESULT_ENUM_END;
|
||||
|
||||
impl->current_offset = index & trans->input_buffer->mask;
|
||||
|
||||
spa_ringbuffer_read_data (trans->input_buffer,
|
||||
trans->input_data,
|
||||
impl->current_offset,
|
||||
impl->current_index & trans->input_buffer->mask,
|
||||
&impl->current,
|
||||
sizeof (SpaEvent));
|
||||
|
||||
|
|
@ -270,10 +267,10 @@ pinos_transport_parse_event (PinosTransport *trans,
|
|||
|
||||
spa_ringbuffer_read_data (trans->input_buffer,
|
||||
trans->input_data,
|
||||
impl->current_offset,
|
||||
impl->current_index & trans->input_buffer->mask,
|
||||
event,
|
||||
size);
|
||||
spa_ringbuffer_read_advance (trans->input_buffer, size);
|
||||
spa_ringbuffer_read_update (trans->input_buffer, impl->current_index + size);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue