shithub: drawterm

Download patch

ref: ae6b4b42ff8ce93c060df1610bb762860a7f211c
parent: 6b188c0bae7c110cc1e7216d8688a652cd0df0cc
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Dec 10 09:45:02 EST 2016

devcons, devkbd: use tas() to check for unuse

--- a/kern/devcons.c	Sat Dec 10 09:42:01 2016
+++ b/kern/devcons.c	Sat Dec 10 09:45:02 2016
@@ -16,8 +16,7 @@
 Queue*	kbdq;			/* unprocessed console input */
 Queue*	lineq;			/* processed console input */
 Queue*	kprintoq;		/* console output, for /dev/kprint */
-long	kprintinuse;		/* test and set whether /dev/kprint is open */
-Lock	kprintlock;
+int	kprintinuse;		/* test and set whether /dev/kprint is open */
 
 int	panicking;
 
@@ -420,14 +419,10 @@
 		break;
 
 	case Qkprint:
-		lock(&kprintlock);
-		if(kprintinuse != 0){
+		if(tas(&kprintinuse) != 0){
 			c->flag &= ~COPEN;
-			unlock(&kprintlock);
 			error(Einuse);
 		}
-		kprintinuse = 1;
-		unlock(&kprintlock);
 		if(kprintoq == nil){
 			kprintoq = qopen(8*1024, Qcoalesce, 0, 0);
 			if(kprintoq == nil){
--- a/kern/devkbd.c	Sat Dec 10 09:42:01 2016
+++ b/kern/devkbd.c	Sat Dec 10 09:45:02 2016
@@ -69,11 +69,10 @@
 	c = devopen(c, omode, kbddir, nelem(kbddir), devgen);
 	switch((ulong)c->qid.path){
 	case Qkbd:
-		if(kbdinuse){
+		if(tas(&kbdinuse) != 0){
 			c->flag &= ~COPEN;
 			error(Einuse);
 		}
-		kbdinuse = 1;
 		break;
 	}
 	return c;