[vlc-devel] [PATCH v4 15/23] vout/control: keep the lock instead of setting a held flag

Steve Lhomme robux4 at ycbcr.xyz
Fri Aug 21 11:59:33 CEST 2020


The code calling vout_control_Hold holds the lock until vout_control_Release is
called. vout_control_Pop() doesn't need to wait for it. If it has the lock no
other code is "holding" it.

Now vout_control_Release() doesn't wake up the vout_control_Pop() directly.
Either commands were added and wait_request was signaled. Or nothing was done
and it doesn't need to wake up vout_control_Pop(). It will be unblocked by new
commands, a vout_control_Wake call or a deadline timeout.
---
 src/video_output/control.c | 17 -----------------
 src/video_output/control.h |  3 ---
 2 files changed, 20 deletions(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index 190792a472a..55e43cbfa47 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -41,10 +41,7 @@ void vout_control_Init(vout_control_t *ctrl)
 {
     vlc_mutex_init(&ctrl->lock);
     vlc_cond_init(&ctrl->wait_request);
-    vlc_cond_init(&ctrl->wait_available);
 
-    ctrl->is_held = false;
-    ctrl->is_waiting = false;
     ctrl->is_dead = false;
     ctrl->can_sleep = true;
     ARRAY_INIT(ctrl->cmd);
@@ -92,18 +89,10 @@ void vout_control_PushVoid(vout_control_t *ctrl, int type)
 void vout_control_Hold(vout_control_t *ctrl)
 {
     vlc_mutex_lock(&ctrl->lock);
-    while (ctrl->is_held || !ctrl->is_waiting)
-        vlc_cond_wait(&ctrl->wait_available, &ctrl->lock);
-    ctrl->is_held = true;
-    vlc_mutex_unlock(&ctrl->lock);
 }
 
 void vout_control_Release(vout_control_t *ctrl)
 {
-    vlc_mutex_lock(&ctrl->lock);
-    assert(ctrl->is_held);
-    ctrl->is_held = false;
-    vlc_cond_signal(&ctrl->wait_available);
     vlc_mutex_unlock(&ctrl->lock);
 }
 
@@ -115,16 +104,10 @@ int vout_control_Pop(vout_control_t *ctrl, vout_control_cmd_t *cmd,
     if (ctrl->cmd.i_size <= 0) {
         /* Spurious wakeups are perfectly fine */
         if (deadline != INVALID_DEADLINE && ctrl->can_sleep) {
-            ctrl->is_waiting = true;
-            vlc_cond_signal(&ctrl->wait_available);
             vlc_cond_timedwait(&ctrl->wait_request, &ctrl->lock, deadline);
-            ctrl->is_waiting = false;
         }
     }
 
-    while (ctrl->is_held)
-        vlc_cond_wait(&ctrl->wait_available, &ctrl->lock);
-
     bool has_cmd;
     if (ctrl->cmd.i_size > 0) {
         has_cmd = true;
diff --git a/src/video_output/control.h b/src/video_output/control.h
index 78a41502c5d..a635be29e50 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -45,13 +45,10 @@ void vout_control_cmd_Init(vout_control_cmd_t *, int type);
 typedef struct {
     vlc_mutex_t lock;
     vlc_cond_t  wait_request;
-    vlc_cond_t  wait_available;
 
     /* */
     bool is_dead;
     bool can_sleep;
-    bool is_waiting;
-    bool is_held;
     DECL_ARRAY(vout_control_cmd_t) cmd;
 } vout_control_t;
 
-- 
2.26.2



More information about the vlc-devel mailing list