[Nickle] nickle: Branch 'master' - 2 commits

Keith Packard keithp at keithp.com
Wed Mar 26 23:24:02 PDT 2008


 file.c   |   26 +++++++++++++++++++++-----
 io.c     |   49 ++++++++++++++++++++++++++-----------------------
 nickle.h |    2 ++
 3 files changed, 49 insertions(+), 28 deletions(-)

New commits:
commit d0604e797cf194eb025a1784766ebea8cf38ec87
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Mar 26 23:21:41 2008 -0700

    Allow background nickle to not poll on tty ownership
    
    When stdin is connected to a terminal but nickle is not the foreground
    process on that terminal, the io code would poll to wait for ownership to
    flip back to nickle so that reads could be performed without generating a
    signal. Now, nickle waits until someone actually tries to read from the
    terminal before starting to poll. This means that simple background
    processing nickle programs will not poll every 100ms.

diff --git a/file.c b/file.c
index 2ba4b5b..11c344f 100644
--- a/file.c
+++ b/file.c
@@ -29,7 +29,7 @@
 
 ReferencePtr	fileBlockedReference;
 Value		fileBlocked;
-Bool		anyFileWriteBlocked;
+Bool		stdinOwned, stdinPolling;
 #ifdef NO_PIPE_SIGIO
 Bool		anyPipeReadBlocked;
 #endif
@@ -952,8 +952,12 @@ FileIsReadable (int fd)
     int		    n;
     struct timeval  tv;
 
-    if (fd < 3 && !ownTty[fd])
+    if (fd == 0 && !stdinOwned)
+    {
+	if (!stdinPolling)
+	    IoNoticeTtyUnowned ();
 	return False;
+    }
     do
     {
 	FD_ZERO (&bits);
@@ -1892,7 +1896,7 @@ FileCheckBlocked (Bool block)
 	    continue;
 	}
 	prev = &blocked->file.next;
-	if (fd < 3 && !ownTty[fd])
+	if (fd == 0 && !stdinOwned)
 	    continue;
 	if (blocked->file.flags & FileInputBlocked)
 	    FD_SET (fd, &readable);
diff --git a/io.c b/io.c
index b7b1d99..d5c218a 100644
--- a/io.c
+++ b/io.c
@@ -15,9 +15,10 @@
 #include	"ref.h"
 
 volatile Bool	signalIo;
-Bool		ownTty[3];
-Bool		anyTtyUnowned;
+Bool		stdinOwned;
+Bool		stdinPolling;
 Bool		ioTimeoutQueued;
+Bool		anyFileWriteBlocked;
 
 #ifdef HAVE_SIGACTION
 #define RESTART_SIGNAL(sig,func)
@@ -41,14 +42,11 @@ IoInterrupt (void)
 void
 IoStop (void)
 {
-    int	fd;
-
-    for (fd = 0; fd < 3; fd++)
+    if (stdin_interactive)
     {
-	ownTty[fd] = False;
-	FileResetFd (fd);
+	FileResetFd (0);
+	stdinOwned = False;
     }
-    anyTtyUnowned = True;
 }
 
 #ifdef GETPGRP_VOID
@@ -71,20 +69,15 @@ IoOwnTty (int fd)
 void
 IoStart (void)
 {
-    int	fd;
-    
-    anyTtyUnowned = False;
-    for (fd = 0; fd < 3; fd++)
+    if (stdin_interactive) 
     {
-        ownTty[fd] = IoOwnTty (fd);
-        if (!ownTty[fd])
-	    anyTtyUnowned = True;
+	stdinOwned = IoOwnTty (0);
+	if (stdinOwned)
+	{
+	    stdinPolling = False;
+	    FileSetFd (0);
+	}
     }
-    if (anyTtyUnowned)
-	IoNoticeTtyUnowned ();
-    else if (stdin_interactive)
-	for (fd = 0; fd < 3; fd++)
-	    FileSetFd (fd);
 }
 
 void
@@ -103,10 +96,10 @@ Value   FileStdin, FileStdout, FileStderr;
 Bool
 IoTimeout (void *closure)
 {
-    if (anyTtyUnowned)
+    if (!stdinOwned)
 	IoStart ();
     FileCheckBlocked (False);
-    if (anyFileWriteBlocked || anyTtyUnowned
+    if (anyFileWriteBlocked || (!stdinOwned && stdinPolling)
 #ifdef NO_PIPE_SIGIO
 	|| anyPipeReadBlocked 
 #endif
@@ -129,7 +122,11 @@ IoSetupTimeout (void)
 void
 IoNoticeTtyUnowned (void)
 {
-    IoSetupTimeout();
+    if (!stdinOwned && !stdinPolling)
+    {
+	stdinPolling = True;
+	IoSetupTimeout();
+    }
 }
 
 void
commit fd8d02af5bf2884858108421fec40b8c7ca9863b
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Mar 26 16:22:44 2008 -0700

    Remove support for non-SIGIO pipes
    
    Older version of the kernel (before 2001) failed to generate SIGIO on pipes,
    so nickle had code to poll instead. I think we can safely remove that code
    now.

diff --git a/file.c b/file.c
index cd6d693..2ba4b5b 100644
--- a/file.c
+++ b/file.c
@@ -1,5 +1,3 @@
-/* $Header$ */
-
 /*
  * Copyright © 1988-2004 Keith Packard and Bart Massey.
  * All Rights Reserved.  See the file COPYING in this directory
@@ -32,7 +30,9 @@
 ReferencePtr	fileBlockedReference;
 Value		fileBlocked;
 Bool		anyFileWriteBlocked;
+#ifdef NO_PIPE_SIGIO
 Bool		anyPipeReadBlocked;
+#endif
 extern Bool	ownTty[3];
 
 typedef struct _FileErrorMap {
@@ -1876,7 +1876,9 @@ FileCheckBlocked (Bool block)
     Value	    blocked, *prev;
     Bool	    ready;
     Bool	    writeBlocked;
+#ifdef NO_PIPE_SIGIO
     Bool	    readPipeBlocked;
+#endif
     
     FD_ZERO (&readable);
     FD_ZERO (&writable);
@@ -1915,12 +1917,16 @@ FileCheckBlocked (Bool block)
     else
     {
 	anyFileWriteBlocked = False;
+#ifdef NO_PIPE_SIGIO
 	anyPipeReadBlocked = False;
+#endif
     }
     if (n > 0)
     {
 	writeBlocked = False;
+#ifdef NO_PIPE_SIGIO
 	readPipeBlocked = False;
+#endif
 	for (prev = &fileBlocked; (blocked = *prev); )
 	{
 	    fd = blocked->file.fd;
@@ -1940,9 +1946,11 @@ FileCheckBlocked (Bool block)
 	    }
 	    if (blocked->file.flags & FileOutputBlocked)
 		writeBlocked = True;
+#ifdef NO_PIPE_SIGIO
 	    if (blocked->file.flags & FileInputBlocked &&
 		blocked->file.flags & FileIsPipe)
 		readPipeBlocked = True;
+#endif
 	    if (ready)
 		ThreadsWakeup (blocked, WakeAll);
 	    if ((blocked->file.flags & (FileOutputBlocked|FileInputBlocked)) == 0)
@@ -1951,7 +1959,9 @@ FileCheckBlocked (Bool block)
 		prev = &blocked->file.next;
 	}
 	anyFileWriteBlocked = writeBlocked;
+#ifdef NO_PIPE_SIGIO
 	anyPipeReadBlocked = readPipeBlocked;
+#endif
     }
     EXIT ();
 }
@@ -1964,6 +1974,7 @@ FileSetBlocked (Value file, int flag)
 	anyFileWriteBlocked = True;
 	IoNoticeWriteBlocked ();
     }
+#ifdef NO_PIPE_SIGIO
     if (flag == FileInputBlocked && 
 	(file->file.flags & FileIsPipe) && 
 	!anyPipeReadBlocked)
@@ -1971,6 +1982,7 @@ FileSetBlocked (Value file, int flag)
 	anyPipeReadBlocked = True;
 	IoNoticeReadBlocked ();
     }
+#endif
     if (file->file.flags & (FileOutputBlocked|FileInputBlocked))
     {
 	file->file.flags |= flag;
diff --git a/io.c b/io.c
index 2c16eed..b7b1d99 100644
--- a/io.c
+++ b/io.c
@@ -106,7 +106,11 @@ IoTimeout (void *closure)
     if (anyTtyUnowned)
 	IoStart ();
     FileCheckBlocked (False);
-    if (anyFileWriteBlocked || anyPipeReadBlocked || anyTtyUnowned)
+    if (anyFileWriteBlocked || anyTtyUnowned
+#ifdef NO_PIPE_SIGIO
+	|| anyPipeReadBlocked 
+#endif
+	)
 	return True;
     ioTimeoutQueued = False;
     return False;
@@ -134,11 +138,13 @@ IoNoticeWriteBlocked (void)
     IoSetupTimeout ();
 }
 
+#ifdef NO_PIPE_SIGIO
 void
 IoNoticeReadBlocked (void)
 {
     IoSetupTimeout ();
 }
+#endif
 
 void
 IoInit (void)
diff --git a/nickle.h b/nickle.h
index 09131c1..610019d 100644
--- a/nickle.h
+++ b/nickle.h
@@ -681,7 +681,9 @@ void	IoStop (void);
 void	IoFini (void);
 Bool	IoTimeout (void *);
 void	IoNoticeWriteBlocked (void);
+#ifdef NO_PIPE_SIGIO
 void	IoNoticeReadBlocked (void);
+#endif
 void	IoNoticeTtyUnowned (void);
 void	IoInterrupt (void);
 


More information about the Nickle mailing list