[vlc-devel] [PATCH v4 9/9] video_output:control: merge the two wait conditions
Steve Lhomme
robux4 at ycbcr.xyz
Fri Dec 18 08:38:28 UTC 2020
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.
---
src/video_output/control.c | 25 ++++++++++++++-----------
src/video_output/control.h | 2 --
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/video_output/control.c b/src/video_output/control.c
index 10bf6d8b033..746bd625705 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->can_sleep = true;
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->can_sleep = false;
- 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->can_sleep) {
- 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 35e8aad6528..5cd99040a84 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -28,12 +28,10 @@
/* */
typedef struct {
vlc_mutex_t lock;
- vlc_cond_t wait_request;
vlc_cond_t wait_available;
/* */
bool can_sleep;
- bool is_waiting;
bool is_held;
DECL_ARRAY(vlc_mouse_t) cmd;
} vout_control_t;
--
2.29.2
More information about the vlc-devel
mailing list