From 4af4effb3148c0c695e56ad1f8ea294996915aa8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Deuc=D0=B5?= <shurd@sasktel.net>
Date: Sun, 14 May 2023 23:26:05 -0400
Subject: [PATCH] Fix deadlock in SDL mode.

sdl_getscaling() does not require vstatlock.  Move it out.
---
 src/conio/sdl_con.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/conio/sdl_con.c b/src/conio/sdl_con.c
index e3b11026c0..6d4b6ee1c7 100644
--- a/src/conio/sdl_con.c
+++ b/src/conio/sdl_con.c
@@ -405,8 +405,8 @@ static void
 update_cvstat(struct video_stats *vs)
 {
 	if (vs != NULL && vs != &vstat) {
-		pthread_mutex_lock(&vstatlock);
 		vstat.scaling = sdl_getscaling();
+		pthread_mutex_lock(&vstatlock);
 		*vs = vstat;
 		pthread_mutex_unlock(&vstatlock);
 	}
@@ -435,15 +435,18 @@ static void internal_setwinsize(struct video_stats *vs, bool force)
 		vs->winwidth = vstat.winwidth = w;
 		vs->winheight = vstat.winheight = h;
 	}
-	if (!changed) {
+	if (changed) {
+		pthread_mutex_unlock(&vstatlock);
+	}
+	else {
 		pthread_mutex_lock(&win_mutex);
 		sdl.GetWindowSize(win, &w, &h);
 		pthread_mutex_unlock(&win_mutex);
 		if (w != vs->winwidth || h != vs->winheight)
 			changed = true;
+		pthread_mutex_unlock(&vstatlock);
 		vstat.scaling = sdl_getscaling();
 	}
-	pthread_mutex_unlock(&vstatlock);
 	if (changed)
 		setup_surfaces(vs);
 }
@@ -651,9 +654,7 @@ static void setup_surfaces(struct video_stats *vs)
 		sdl.PeepEvents(&ev, 1, SDL_ADDEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT);
 	}
 	pthread_mutex_unlock(&win_mutex);
-	pthread_mutex_lock(&vstatlock);
 	vstat.scaling = sdl_getscaling();
-	pthread_mutex_unlock(&vstatlock);
 }
 
 /* Called from event thread only */
-- 
GitLab