changeset 54029:812301ea706a

(in_read_avail_input): New static variable to handle re-entrancy. (read_avail_input): Change buf to pinter to read_avail_input_buf. Use in_read_avail_input to handle re-entrance; when re-entered, fully initialize and use tmp_buf array instead of read_avail_input_buf.
author Kim F. Storm <storm@cua.dk>
date Tue, 17 Feb 2004 00:29:13 +0000
parents 77c2c4eceb79
children c97510dccd0d
files src/keyboard.c
diffstat 1 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/keyboard.c	Tue Feb 17 00:28:22 2004 +0000
+++ b/src/keyboard.c	Tue Feb 17 00:29:13 2004 +0000
@@ -6581,13 +6581,17 @@
      int expected;
 {
   struct input_event *buf = read_avail_input_buf;
+  struct input_event tmp_buf[KBD_BUFFER_SIZE];
   register int i;
   int nread;
 
   /* Trivial hack to make read_avail_input re-entrant.  */
-  if (in_read_avail_input)
-    return 0;
-  in_read_avail_input = 1;
+  if (in_read_avail_input++)
+    {
+      buf = tmp_buf;
+      for (i = 0; i < KBD_BUFFER_SIZE; i++)
+	EVENT_INIT (buf[i]);
+    }
 
   if (read_socket_hook)
     /* No need for FIONREAD or fcntl; just say don't wait.  */
@@ -6602,12 +6606,16 @@
 
       /* Determine how many characters we should *try* to read.  */
 #ifdef WINDOWSNT
-      return (in_read_avail_input = 0);
+      --in_read_avail_input;
+      return 0;
 #else /* not WINDOWSNT */
 #ifdef MSDOS
       n_to_read = dos_keysns ();
       if (n_to_read == 0)
-	return (in_read_avail_input = 0);
+	{
+	  --in_read_avail_input;
+	  return 0;
+	}
 #else /* not MSDOS */
 #ifdef FIONREAD
       /* Find out how much input is available.  */
@@ -6625,7 +6633,10 @@
 	    n_to_read = 0;
 	}
       if (n_to_read == 0)
-	return (in_read_avail_input = 0);
+	{
+	  --in_read_avail_input;
+	  return 0;
+	}
       if (n_to_read > sizeof cbuf)
 	n_to_read = sizeof cbuf;
 #else /* no FIONREAD */
@@ -6717,10 +6728,10 @@
     }
 
   /* Clear used events */
-  for (i = 0; i < nread; i++)
-    EVENT_INIT (buf[i]);
-
-  in_read_avail_input = 0;
+  if (--in_read_avail_input == 0)
+    for (i = 0; i < nread; i++)
+      EVENT_INIT (buf[i]);
+
   return nread;
 }
 #endif /* not VMS */