GUACAMOLE-377: Do NOT acquire the ops lock before any frame lock.

This commit is contained in:
Michael Jumper 2024-06-13 00:39:33 -07:00
parent 58140721ea
commit b965c4dd24
2 changed files with 17 additions and 8 deletions

View File

@ -224,10 +224,13 @@ void guac_display_end_multiple_frames(guac_display* display, int frames) {
/* Defer rendering of further frames until after any in-progress frame has
* finished. Graphical changes will meanwhile continue being accumulated in
* the pending frame. */
guac_fifo_lock(&display->ops);
if (display->ops.state.value & GUAC_FIFO_STATE_NONEMPTY || display->active_workers) {
goto finished_with_display_ops;
}
int encoding_in_progress = display->ops.state.value & GUAC_FIFO_STATE_NONEMPTY || display->active_workers;
guac_fifo_unlock(&display->ops);
if (encoding_in_progress)
goto finished_with_pending_frame_lock;
guac_rwlock_acquire_write_lock(&display->last_frame.lock);
@ -286,8 +289,7 @@ void guac_display_end_multiple_frames(guac_display* display, int frames) {
finished_with_last_frame_lock:
guac_rwlock_release_lock(&display->last_frame.lock);
finished_with_display_ops:
guac_fifo_unlock(&display->ops);
finished_with_pending_frame_lock:
guac_rwlock_release_lock(&display->pending_frame.lock);
if (plan != NULL) {

View File

@ -73,9 +73,16 @@
/*
* IMPORTANT: In cases where a single thread must acquire BOTH the pending
* frame lock and the last frame lock, the pending frame lock MUST be acquired
* first to maintain consistent lock order and avoid deadlock conditions. All
* functions within guac_display will follow this order.
* frame lock and the last frame lock, proper acquisition order must be
* observed to avoid deadlock. The correct order is:
*
* 1) pending_frame.lock
* 2) last_frame.lock
*
* The lock for the ops FIFO must NEVER be acquired before either of the frame
* locks. All operations involving the ops FIFO should be performed quickly
* and, if either pending_frame or last_frame must be involved, those locks
* must be acquired first. Doing otherwise risks deadlock.
*/
/**