[vlc-commits] mmal: Use atomic operations for refcounting
Julian Scheel
git at videolan.org
Fri Jun 5 15:37:14 CEST 2015
vlc | branch: master | Julian Scheel <julian at jusst.de> | Wed Jun 3 09:37:34 2015 +0200| [73a216048dc36e6c6813ff056d13ae2f3adc947d] | committer: Jean-Baptiste Kempf
mmal: Use atomic operations for refcounting
Signed-off-by: Julian Scheel <julian at jusst.de>
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=73a216048dc36e6c6813ff056d13ae2f3adc947d
---
modules/hw/mmal/codec.c | 8 ++++----
modules/hw/mmal/deinterlace.c | 9 +++++----
modules/hw/mmal/vout.c | 8 +++-----
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/modules/hw/mmal/codec.c b/modules/hw/mmal/codec.c
index 183981c..36af836 100644
--- a/modules/hw/mmal/codec.c
+++ b/modules/hw/mmal/codec.c
@@ -438,7 +438,7 @@ static int send_output_buffer(decoder_t *dec)
ret = -1;
goto err;
}
- sys->output_in_transit++;
+ atomic_fetch_add(&sys->output_in_transit, 1);
return ret;
@@ -456,7 +456,7 @@ static void fill_output_port(decoder_t *dec)
unsigned max_buffers_in_transit = __MAX(sys->output_pool->headers_num,
MIN_NUM_BUFFERS_IN_TRANSIT);
unsigned buffers_available = mmal_queue_length(sys->output_pool->queue);
- unsigned buffers_to_send = max_buffers_in_transit - sys->output_in_transit;
+ unsigned buffers_to_send = max_buffers_in_transit - atomic_load(&sys->output_in_transit);
unsigned i;
if (buffers_to_send > buffers_available)
@@ -464,7 +464,7 @@ static void fill_output_port(decoder_t *dec)
#ifndef NDEBUG
msg_Dbg(dec, "Send %d buffers to output port (available: %d, in_transit: %d, buffer_num: %d)",
- buffers_to_send, buffers_available, sys->output_in_transit,
+ buffers_to_send, buffers_available, atomic_load(&sys->output_in_transit),
sys->output->buffer_num);
#endif
for (i = 0; i < buffers_to_send; ++i)
@@ -656,7 +656,7 @@ static void output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
buffer->data = NULL;
mmal_buffer_header_release(buffer);
}
- sys->output_in_transit--;
+ atomic_fetch_sub(&sys->output_in_transit, 1);
} else if (buffer->cmd == MMAL_EVENT_FORMAT_CHANGED) {
fmt = mmal_event_format_changed_get(buffer);
diff --git a/modules/hw/mmal/deinterlace.c b/modules/hw/mmal/deinterlace.c
index d8e3172..2ba63cd 100644
--- a/modules/hw/mmal/deinterlace.c
+++ b/modules/hw/mmal/deinterlace.c
@@ -30,6 +30,7 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_filter.h>
+#include <vlc_atomic.h>
#include "mmal_picture.h"
@@ -382,7 +383,7 @@ static int send_output_buffer(filter_t *filter)
picture_Release(picture);
ret = -1;
} else {
- sys->output_in_transit++;
+ atomic_fetch_add(&sys->output_in_transit, 1);
vlc_cond_signal(&sys->buffer_cond);
}
vlc_mutex_unlock(&sys->buffer_cond_mutex);
@@ -471,7 +472,7 @@ static picture_t *deinterlace(filter_t *filter, picture_t *picture)
msg_Err(filter, "Failed to send buffer to input port (status=%"PRIx32" %s)",
status, mmal_status_to_string(status));
} else {
- sys->input_in_transit++;
+ atomic_fetch_add(&sys->input_in_transit, 1);
vlc_cond_signal(&sys->buffer_cond);
}
vlc_mutex_unlock(&sys->buffer_cond_mutex);
@@ -527,7 +528,7 @@ static void input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
if (picture)
picture_Release(picture);
- sys->input_in_transit--;
+ atomic_fetch_sub(&sys->input_in_transit, 1);
vlc_cond_signal(&sys->buffer_cond);
vlc_mutex_unlock(&sys->buffer_cond_mutex);
}
@@ -548,7 +549,7 @@ static void output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
buffer->user_data = NULL;
}
- sys->output_in_transit--;
+ atomic_fetch_sub(&sys->output_in_transit, 1);
vlc_cond_signal(&sys->buffer_cond);
vlc_mutex_unlock(&sys->buffer_cond_mutex);
} else if (buffer->cmd == MMAL_EVENT_FORMAT_CHANGED) {
diff --git a/modules/hw/mmal/vout.c b/modules/hw/mmal/vout.c
index 569b8a3..6654db2 100644
--- a/modules/hw/mmal/vout.c
+++ b/modules/hw/mmal/vout.c
@@ -564,12 +564,10 @@ static void vd_display(vout_display_t *vd, picture_t *picture,
buffer->cmd = 0;
buffer->length = sys->input->buffer_size;
- vlc_mutex_lock(&sys->buffer_mutex);
status = mmal_port_send_buffer(sys->input, buffer);
if (status == MMAL_SUCCESS)
- ++sys->buffers_in_transit;
+ atomic_fetch_add(&sys->buffers_in_transit, 1);
- vlc_mutex_unlock(&sys->buffer_mutex);
if (status != MMAL_SUCCESS) {
msg_Err(vd, "Failed to send buffer to input port. Frame dropped");
picture_Release(picture);
@@ -590,7 +588,7 @@ static void vd_display(vout_display_t *vd, picture_t *picture,
sys->next_phase_check = (sys->next_phase_check + 1) % PHASE_CHECK_INTERVAL;
vlc_mutex_lock(&sys->buffer_mutex);
- while (sys->buffers_in_transit >= MAX_BUFFERS_IN_TRANSIT)
+ while (atomic_load(&sys->buffers_in_transit) >= MAX_BUFFERS_IN_TRANSIT)
vlc_cond_wait(&sys->buffer_cond, &sys->buffer_mutex);
vlc_mutex_unlock(&sys->buffer_mutex);
}
@@ -688,7 +686,7 @@ static void input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
picture_Release(picture);
vlc_mutex_lock(&sys->buffer_mutex);
- --sys->buffers_in_transit;
+ atomic_fetch_sub(&sys->buffers_in_transit, 1);
vlc_cond_signal(&sys->buffer_cond);
vlc_mutex_unlock(&sys->buffer_mutex);
}
More information about the vlc-commits
mailing list