[vlc-commits] [Git][videolan/vlc][master] 3 commits: vout: rename "is_waiting" to "yielding"
Romain Vimont (@rom1v)
gitlab at videolan.org
Wed Jul 7 10:28:01 UTC 2021
Romain Vimont pushed to branch master at VideoLAN / VLC
Commits:
936bceb9 by Romain Vimont at 2021-07-07T09:51:39+00:00
vout: rename "is_waiting" to "yielding"
This highlights that the flag is true when the vout thread is yielding
execution to another thread waiting on vout_control_Enter().
Avoiding the term "waiting" will allow to avoid confusion in next
commits when a new flag will be added.
- - - - -
036567a9 by Romain Vimont at 2021-07-07T09:51:39+00:00
vout: document a wait condition
The wait condition is not related to a single flag, but two. Document
the condition in a comment.
- - - - -
8fe76a5b by Romain Vimont at 2021-07-07T09:51:39+00:00
vout: always pass vout_control_Hold()
A thread calling vout_control_Hold() may only pass while
vout_control_Pop() is waiting.
Since f1bf7ce5b4480a3d38d54c7ae1d1564f0670d83f, in practice, it almost
never waits, so vout_control_Hold() may be blocked for a long time.
If there is at least one thread waiting on vout_control_Hold(), make
the vout thread wait from vout_control_Pop().
Fixes #25694
- - - - -
2 changed files:
- src/video_output/control.c
- src/video_output/control.h
Changes:
=====================================
src/video_output/control.c
=====================================
@@ -37,8 +37,9 @@ void vout_control_Init(vout_control_t *ctrl)
vlc_cond_init(&ctrl->wait_available);
ctrl->is_held = false;
- ctrl->is_waiting = false;
+ ctrl->yielding = false;
ctrl->forced_awake = false;
+ ctrl->pending_count = 0;
ARRAY_INIT(ctrl->cmd);
}
@@ -67,9 +68,14 @@ void vout_control_Wake(vout_control_t *ctrl)
void vout_control_Hold(vout_control_t *ctrl)
{
vlc_mutex_lock(&ctrl->lock);
- while (ctrl->is_held || !ctrl->is_waiting)
+ ++ctrl->pending_count;
+ vlc_cond_signal(&ctrl->wait_request);
+ while (ctrl->is_held || !ctrl->yielding)
vlc_cond_wait(&ctrl->wait_available, &ctrl->lock);
ctrl->is_held = true;
+ --ctrl->pending_count;
+ if (ctrl->pending_count == 0)
+ vlc_cond_signal(&ctrl->wait_request);
vlc_mutex_unlock(&ctrl->lock);
}
@@ -87,14 +93,32 @@ 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);
- if (ctrl->cmd.i_size <= 0) {
- /* Spurious wakeups are perfectly fine */
- if (deadline != VLC_TICK_INVALID && !ctrl->forced_awake) {
- ctrl->is_waiting = true;
+ bool timed_out = false;
+ for (;;)
+ {
+ if (ctrl->forced_awake)
+ break;
+
+ if (ctrl->pending_count != 0)
+ {
+ /* Let vout_control_Hold() callers pass */
+ ctrl->yielding = true;
+ vlc_cond_signal(&ctrl->wait_available);
+ vlc_cond_wait(&ctrl->wait_request, &ctrl->lock);
+ ctrl->yielding = false;
+ }
+ else if (timed_out)
+ break;
+ else if (ctrl->cmd.i_size <= 0 && deadline != VLC_TICK_INVALID)
+ {
+ ctrl->yielding = true;
vlc_cond_signal(&ctrl->wait_available);
- vlc_cond_timedwait(&ctrl->wait_request, &ctrl->lock, deadline);
- ctrl->is_waiting = false;
+ timed_out =
+ vlc_cond_timedwait(&ctrl->wait_request, &ctrl->lock, deadline);
+ ctrl->yielding = false;
}
+ else
+ break;
}
while (ctrl->is_held)
=====================================
src/video_output/control.h
=====================================
@@ -28,13 +28,14 @@
/* */
typedef struct {
vlc_mutex_t lock;
- vlc_cond_t wait_request;
- vlc_cond_t wait_available;
+ vlc_cond_t wait_request;
+ vlc_cond_t wait_available; /* available: yielding && !is_held */
/* */
bool forced_awake;
- bool is_waiting;
+ bool yielding;
bool is_held;
+ unsigned pending_count;
DECL_ARRAY(vlc_mouse_t) cmd;
} vout_control_t;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3af1b9dc30bcf6e378d81fc1229bd3f8ad3bf363...8fe76a5b9675809874d361f858b2b6b6362ffca4
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3af1b9dc30bcf6e378d81fc1229bd3f8ad3bf363...8fe76a5b9675809874d361f858b2b6b6362ffca4
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list