[vlc-commits] mmal/deinterlace: Replace cond_signal with vlc_sem

Julian Scheel git at videolan.org
Thu Oct 19 11:38:37 CEST 2017


vlc | branch: master | Julian Scheel <julian at jusst.de> | Thu Oct 19 11:23:02 2017 +0200| [173e44e8f2fc58fc3635b75190e501f49f0851ed] | committer: Jean-Baptiste Kempf

mmal/deinterlace: Replace cond_signal with vlc_sem

Simply locking code by using vlc_sem_t. Also removes the peviously
unused sys->mutex instance.

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=173e44e8f2fc58fc3635b75190e501f49f0851ed
---

 modules/hw/mmal/deinterlace.c | 36 ++++++++++--------------------------
 1 file changed, 10 insertions(+), 26 deletions(-)

diff --git a/modules/hw/mmal/deinterlace.c b/modules/hw/mmal/deinterlace.c
index 4caf508d3a..ad75297e5c 100644
--- a/modules/hw/mmal/deinterlace.c
+++ b/modules/hw/mmal/deinterlace.c
@@ -60,9 +60,7 @@ struct filter_sys_t {
     MMAL_PORT_T *output;
 
     MMAL_QUEUE_T *filtered_pictures;
-    vlc_mutex_t mutex;
-    vlc_mutex_t buffer_cond_mutex;
-    vlc_cond_t buffer_cond;
+    vlc_sem_t sem;
 
     atomic_bool started;
 
@@ -232,9 +230,8 @@ static int Open(filter_t *filter)
 
     filter->pf_video_filter = deinterlace;
     filter->pf_flush = flush;
-    vlc_mutex_init_recursive(&sys->mutex);
-    vlc_mutex_init(&sys->buffer_cond_mutex);
-    vlc_cond_init(&sys->buffer_cond);
+
+    vlc_sem_init(&sys->sem, 0);
 
 out:
     if (ret != VLC_SUCCESS)
@@ -274,9 +271,7 @@ static void Close(filter_t *filter)
     if (sys->component)
         mmal_component_release(sys->component);
 
-    vlc_mutex_destroy(&sys->mutex);
-    vlc_mutex_destroy(&sys->buffer_cond_mutex);
-    vlc_cond_destroy(&sys->buffer_cond);
+    vlc_sem_destroy(&sys->sem);
     free(sys);
 
     bcm_host_deinit();
@@ -310,7 +305,6 @@ static int send_output_buffer(filter_t *filter)
 
     mmal_picture_lock(picture);
 
-    vlc_mutex_lock(&sys->buffer_cond_mutex);
     status = mmal_port_send_buffer(sys->output, buffer);
     if (status != MMAL_SUCCESS) {
         msg_Err(filter, "Failed to send buffer to output port (status=%"PRIx32" %s)",
@@ -320,9 +314,8 @@ static int send_output_buffer(filter_t *filter)
         ret = -1;
     } else {
         atomic_fetch_add(&sys->output_in_transit, 1);
-        vlc_cond_signal(&sys->buffer_cond);
+        vlc_sem_post(&sys->sem);
     }
-    vlc_mutex_unlock(&sys->buffer_cond_mutex);
 
 out:
     return ret;
@@ -370,7 +363,6 @@ static picture_t *deinterlace(filter_t *filter, picture_t *picture)
     buffer->cmd = 0;
 
     if (!picture->p_sys->displayed) {
-        vlc_mutex_lock(&sys->buffer_cond_mutex);
         status = mmal_port_send_buffer(sys->input, buffer);
         if (status != MMAL_SUCCESS) {
             msg_Err(filter, "Failed to send buffer to input port (status=%"PRIx32" %s)",
@@ -379,9 +371,8 @@ static picture_t *deinterlace(filter_t *filter, picture_t *picture)
         } else {
             picture->p_sys->displayed = true;
             atomic_fetch_add(&sys->input_in_transit, 1);
-            vlc_cond_signal(&sys->buffer_cond);
+            vlc_sem_post(&sys->sem);
         }
-        vlc_mutex_unlock(&sys->buffer_cond_mutex);
     } else {
         picture_Release(picture);
     }
@@ -427,12 +418,9 @@ static void flush(filter_t *filter)
         mmal_port_flush(sys->input);
 
         msg_Dbg(filter, "flush: wait for all buffers to be returned");
-        vlc_mutex_lock(&sys->buffer_cond_mutex);
         while (atomic_load(&sys->input_in_transit) ||
-                atomic_load(&sys->output_in_transit)) {
-            vlc_cond_wait(&sys->buffer_cond, &sys->buffer_cond_mutex);
-        }
-        vlc_mutex_unlock(&sys->buffer_cond_mutex);
+                atomic_load(&sys->output_in_transit))
+            vlc_sem_wait(&sys->sem);
     }
 
     while ((buffer = mmal_queue_get(sys->filtered_pictures))) {
@@ -464,7 +452,6 @@ static void input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
     filter_t *filter = (filter_t *)port->userdata;
     filter_sys_t *sys = filter->p_sys;
 
-    vlc_mutex_lock(&sys->buffer_cond_mutex);
     if (picture) {
         picture_Release(picture);
     } else {
@@ -473,8 +460,7 @@ static void input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
     }
 
     atomic_fetch_sub(&sys->input_in_transit, 1);
-    vlc_cond_signal(&sys->buffer_cond);
-    vlc_mutex_unlock(&sys->buffer_cond_mutex);
+    vlc_sem_post(&sys->sem);
 }
 
 static void output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
@@ -484,7 +470,6 @@ static void output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
     picture_t *picture;
 
     if (buffer->cmd == 0) {
-        vlc_mutex_lock(&sys->buffer_cond_mutex);
         if (buffer->length > 0) {
             atomic_store(&sys->started, true);
             mmal_queue_put(sys->filtered_pictures, buffer);
@@ -495,8 +480,7 @@ static void output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
         }
 
         atomic_fetch_sub(&sys->output_in_transit, 1);
-        vlc_cond_signal(&sys->buffer_cond);
-        vlc_mutex_unlock(&sys->buffer_cond_mutex);
+        vlc_sem_post(&sys->sem);
     } else if (buffer->cmd == MMAL_EVENT_FORMAT_CHANGED) {
         msg_Warn(filter, "MMAL_EVENT_FORMAT_CHANGED seen but not handled");
         mmal_buffer_header_release(buffer);



More information about the vlc-commits mailing list