code: drawterm

Download patch

ref: 49142f5becabaccddde13dbb00f85f998778a2a4
parent: 36debf46ac184a22c6936345d22e4cfad995948c
author: Jacob Moody <moody@posixcafe.org>
date: Thu Jul 13 07:18:26 EDT 2023

import drawlock fixes from 9front (thanks foura)

These were first found in drawterm commit
54f615f6c0090c7c0011f4121ecf54fcf1e07a6b. In which due to the
locking issues a race was found that crashed the wayland backend.
This turned out to be a bug in devdraw itself and was fixed in 9front
commit e7d03d19100fe3180906c8ce3f2cab3ba9387fe8, in the meantime the
temporary hack in drawterm was reverted. The proper solution was merged
as mentioned but not propigated back to drawterm until now.

This came up again as it was found in some instalations of KDE's
wayland to cause crashes more reliably in resizes.

--- a/gui-wl/wl-screen.c
+++ b/gui-wl/wl-screen.c
@@ -201,8 +201,8 @@
 
 	wl->runing = 1;
 	kproc("wldispatch", dispatchproc, wl);
-	terminit();
 	qlock(&drawlock);
+	terminit();
 	wlflush(wl);
 	wldrawcsd(wl);
 	qunlock(&drawlock);
--- a/kern/devdraw.c
+++ b/kern/devdraw.c
@@ -958,7 +958,6 @@
 void
 deletescreenimage(void)
 {
-	dlock();
 	if(screenimage){
 		/* will be freed via screendimage; disable */
 		screenimage->clipr = ZR;
@@ -968,15 +967,12 @@
 		drawfreedimage(screendimage);
 		screendimage = nil;
 	}
-	dunlock();
 }
 
 void
 resetscreenimage(void)
 {
-	dlock();
 	initscreenimage();
-	dunlock();
 }
 
 static Chan*
--- a/kern/term.c
+++ b/kern/term.c
@@ -44,7 +44,6 @@
 	char *greet;
 	Memimage *grey;
 
-	qlock(&drawlock);
 	back = memwhite;
 	conscol = memblack;
 	memfillcolor(gscreen, 0x444488FF);
@@ -73,7 +72,6 @@
 	curpos = window.min;
 	window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
 	flushmemscreen(gscreen->r);
-	qunlock(&drawlock);
 
 	termscreenputs(kmesg.buf, kmesg.n);
 }
@@ -112,11 +110,11 @@
 			continue;
 		}
 		gscreen->clipr = resize.r;
-		qunlock(&drawlock);
 
 		screenwin();
 		deletescreenimage();
 		resetscreenimage();
+		qunlock(&drawlock);
 		osmsleep(1000);
 	}
 }