[vlc-commits] video_output:control: merge the two wait conditions

Steve Lhomme git at videolan.org
Tue Jan 19 08:56:47 UTC 2021


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Dec 18 07:26:01 2020 +0100| [6d31fe007b20dbe07eba5420de8ec84653c7c7c9] | committer: Steve Lhomme

video_output:control: merge the two wait conditions

The code using the is_held (outside the vout thread doing things on the vout)
is still blocked by the cond_timedwait but doesn't need an extra boolean for
that.

The wait for is_held is done earlier as it's more logical to wait for outside
calls to be finished blocking the vout thread loop before actually waiting for
a deadline, which may have passed anyway. In both cases (before and now), new
calls to control_Hold() were/are blocked until control_Pop() is done.

Moving this code also mimicks better the way control_Hold/control_Release are
using is_held and the (shared) wait condition. Once the timed wait is done we
are back to a (signaled) state similar to control_Release.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6d31fe007b20dbe07eba5420de8ec84653c7c7c9
---

 src/video_output/control.c | 25 ++++++++++++++-----------
 src/video_output/control.h |  4 +---
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/video_output/control.c b/src/video_output/control.c
index 5d72caf60e..eb6fea7681 100644
--- a/src/video_output/control.c
+++ b/src/video_output/control.c
@@ -33,11 +33,9 @@
 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->forced_awake = false;
     ARRAY_INIT(ctrl->cmd);
 }
@@ -52,7 +50,7 @@ void vout_control_PushMouse(vout_control_t *ctrl, const vlc_mouse_t *video_mouse
 {
     vlc_mutex_lock(&ctrl->lock);
     ARRAY_APPEND(ctrl->cmd, *video_mouse);
-    vlc_cond_signal(&ctrl->wait_request);
+    vlc_cond_signal(&ctrl->wait_available);
     vlc_mutex_unlock(&ctrl->lock);
 }
 
@@ -60,14 +58,14 @@ void vout_control_Wake(vout_control_t *ctrl)
 {
     vlc_mutex_lock(&ctrl->lock);
     ctrl->forced_awake = true;
-    vlc_cond_signal(&ctrl->wait_request);
+    vlc_cond_signal(&ctrl->wait_available);
     vlc_mutex_unlock(&ctrl->lock);
 }
 
 void vout_control_Hold(vout_control_t *ctrl)
 {
     vlc_mutex_lock(&ctrl->lock);
-    while (ctrl->is_held || !ctrl->is_waiting)
+    while (ctrl->is_held)
         vlc_cond_wait(&ctrl->wait_available, &ctrl->lock);
     ctrl->is_held = true;
     vlc_mutex_unlock(&ctrl->lock);
@@ -87,19 +85,24 @@ int vout_control_Pop(vout_control_t *ctrl, vlc_mouse_t *mouse, vlc_tick_t deadli
     bool has_cmd = false;
     vlc_mutex_lock(&ctrl->lock);
 
+    while (ctrl->is_held)
+        // wait until code outside the vout thread loop has finished doing things
+        vlc_cond_wait(&ctrl->wait_available, &ctrl->lock);
+
     if (ctrl->cmd.i_size <= 0) {
         /* Spurious wakeups are perfectly fine */
         if (deadline != VLC_TICK_INVALID && !ctrl->forced_awake) {
-            ctrl->is_waiting = true;
+            ctrl->is_held = true;
+            // wait for something to happen while blocking vout_control_Hold
+            // - new mouse state received
+            // - control_Wake called: new picture arrived or terminating vout
+            vlc_cond_timedwait(&ctrl->wait_available, &ctrl->lock, deadline);
+            // allow vout_control_Hold again
+            ctrl->is_held = false;
             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);
-
     if (ctrl->cmd.i_size > 0) {
         has_cmd = true;
         *mouse = ARRAY_VAL(ctrl->cmd, 0);
diff --git a/src/video_output/control.h b/src/video_output/control.h
index e85af59236..ce46454ebe 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -28,13 +28,11 @@
 /* */
 typedef struct {
     vlc_mutex_t lock;
-    vlc_cond_t  wait_request;
     vlc_cond_t  wait_available;
 
     /* */
     bool forced_awake;
-    bool is_waiting;
-    bool is_held;
+    bool is_held; // control FIFO held outside of the vout thread
     DECL_ARRAY(vlc_mouse_t) cmd;
 } vout_control_t;
 



More information about the vlc-commits mailing list