shithub: drawterm

Download patch

ref: 54f615f6c0090c7c0011f4121ecf54fcf1e07a6b
parent: 29c1eaaf69513e62627678aba7ab68c7a5586ef1
author: Jacob Moody <moody@posixcafe.org>
date: Fri Jun 24 22:42:19 EDT 2022

tidy drawlock use

We need to be careful about doing lock transitions,
it's easier to just maintain the lock and call functions
with the locks held.

--- a/kern/devdraw.c
+++ b/kern/devdraw.c
@@ -940,7 +940,7 @@
 	return di;
 }
 
-static int
+int
 initscreenimage(void)
 {
 	if(screenimage != nil)
@@ -956,9 +956,8 @@
 }
 
 void
-deletescreenimage(void)
+_deletescreenimage(void)
 {
-	dlock();
 	if(screenimage){
 		/* will be freed via screendimage; disable */
 		screenimage->clipr = ZR;
@@ -968,6 +967,13 @@
 		drawfreedimage(screendimage);
 		screendimage = nil;
 	}
+}
+
+void
+deletescreenimage(void)
+{
+	dlock();
+	_deletescreenimage();
 	dunlock();
 }
 
@@ -996,8 +1002,6 @@
 static Walkqid*
 drawwalk(Chan *c, Chan *nc, char **name, int nname)
 {
-	if(screenimage == nil)
-		error("no frame buffer");
 	return devwalk(c, nc, name, nname, 0, 0, drawgen);
 }
 
--- a/kern/term.c
+++ b/kern/term.c
@@ -9,6 +9,8 @@
 #include	"screen.h"
 
 extern Memimage		*gscreen;
+int	initscreenimage(void);
+void	_deletescreenimage(void);
 
 static Memsubfont	*memdefont;
 static Lock		screenlock;
@@ -112,22 +114,27 @@
 			continue;
 		}
 		gscreen->clipr = resize.r;
+		_deletescreenimage();
+		initscreenimage();
 		qunlock(&drawlock);
 
 		screenwin();
-		deletescreenimage();
-		resetscreenimage();
-		osmsleep(1000);
 	}
 }
 
 void
-screenresize(Rectangle r)
+_screenresize(Rectangle r)
 {
-	qlock(&drawlock);
 	resize.r = r;
 	resize.f = 1;
 	wakeup(&resize.z);
+}
+
+void
+screenresize(Rectangle r)
+{
+	qlock(&drawlock);
+	_screenresize(r);
 	qunlock(&drawlock);
 }