Subject: Re: MicroEMACS works but eats CPU on SysV
From: [email-masked] (Karl Lehenbauer)
Date: 26 Nov 87 05:04:18 GMT
Newsgroups: comp.sources.bugs

In article <[email-masked]>, I wrote about an apparent problem with
uEMACS under Unix System V.  I dug around and found that they do an 
fcntl to set read with no delay as a means of getting typeahead in
order to figure out to cancel output in progress.  I'm not 100% 
sure that's their object, but that's what it looks like.

Anyway, there's a variable, kbdpoll, which is set to TRUE to indicate
that the input has been set to no delay, O_NDELAY, via fcntl.
When 'typahead' is called, if kbdpoll isn't set, typahead sets it and
calls fcntl with O_NDELAY so it can do the read without wait.  When 
'ttgetc' is called to get a character in the regular manner, if kbdpoll 
is set, ttgetc does an fcntl to turn off O_NDELAY and clears kbdpoll.
The problem is that typahead doesn't set kbdpoll after setting O_NDELAY,
so ttgetc never knows to clear it, resulting in a no-delay loop doing
"while (read(0, &kbdq, 1) != 1);"  

Here's the diff:

490a491
> 		kbdpoll = TRUE;
--