[vlc-devel] [PATCH 09/10] vout: control: turn is_dead into an atomic bool

Steve Lhomme robux4 at ycbcr.xyz
Fri Jul 17 13:50:52 CEST 2020


So we avoid waiting when marking the command array as dead.
---
 src/video_output/control.c | 8 +++-----
 src/video_output/control.h | 2 +-
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index 40f71e81300..52960d66591 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -47,7 +47,7 @@ void vout_control_Init(vout_control_t *ctrl)
     vlc_cond_init(&ctrl->wait_available);
 
     ctrl->is_held = false;
-    ctrl->is_dead = false;
+    atomic_init(&ctrl->is_dead, false);
     ARRAY_INIT(ctrl->cmd);
 }
 
@@ -63,15 +63,13 @@ void vout_control_Clean(vout_control_t *ctrl)
 
 void vout_control_Dead(vout_control_t *ctrl)
 {
-    vlc_mutex_lock(&ctrl->lock);
-    ctrl->is_dead = true;
-    vlc_mutex_unlock(&ctrl->lock);
+    atomic_store(&ctrl->is_dead, true);
 }
 
 static void vout_control_Push(vout_control_t *ctrl, vout_control_cmd_t *cmd)
 {
     vlc_mutex_lock(&ctrl->lock);
-    if (!ctrl->is_dead) {
+    if (!atomic_load(&ctrl->is_dead)) {
         ARRAY_APPEND(ctrl->cmd, *cmd);
     } else {
         vout_control_cmd_Clean(cmd);
diff --git a/src/video_output/control.h b/src/video_output/control.h
index ccdd3eb2ce0..882b887b959 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -51,7 +51,7 @@ typedef struct {
     vlc_cond_t  wait_available;
 
     /* */
-    bool is_dead;
+    atomic_bool is_dead;
     bool is_held;
     DECL_ARRAY(vout_control_cmd_t) cmd;
 } vout_control_t;
-- 
2.26.2



More information about the vlc-devel mailing list