tTweaks for the Macintosh. - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 53dbac948575b07e95d184bbfbe4d8953c5ccc4c
 (DIR) parent 6e2cec77b292cc2285e369ec01faa877ea91dbdd
 (HTM) Author: rsc <devnull@localhost>
       Date:   Tue,  2 Mar 2004 16:58:49 +0000
       
       Tweaks for the Macintosh.
       
       Diffstat:
         M bin/9c                              |       4 +++-
         M src/cmd/9pserve.c                   |       1 -
         M src/lib9/mkfile                     |       1 -
         M src/lib9/quote.c                    |       2 +-
         M src/libthread/fdwait.c              |      88 +++++++++++++++++++++++++++++--
       
       5 files changed, 87 insertions(+), 9 deletions(-)
       ---
 (DIR) diff --git a/bin/9c b/bin/9c
       t@@ -19,7 +19,9 @@ usegcc()
        tag="`uname`-`uname -m`-${CC9:-cc}"
        case "$tag" in
        *BSD*)                usegcc ;;
       -*Darwin*)        usegcc ;;
       +*Darwin*)        usegcc 
       +        cflags=`echo $cflags|sed 's/-ggdb/-g3 -no-cpp-precomp/'`
       +        ;;
        *HP-UX*)        cc=cc; cflags="-g -O -c -Ae" ;;
        *Linux*)        usegcc ;;
        *OSF1*)                cc=cc; cflags="-g -O -c" ;;
 (DIR) diff --git a/src/cmd/9pserve.c b/src/cmd/9pserve.c
       t@@ -2,7 +2,6 @@
        #include <libc.h>
        #include <fcall.h>
        #include <thread.h>
       -#include <poll.h>
        #include <errno.h>
        
        enum
 (DIR) diff --git a/src/lib9/mkfile b/src/lib9/mkfile
       t@@ -10,7 +10,6 @@ NUM=\
        # Could add errfmt, but we want to pick it up from lib9 instead.
        FMTOFILES=\
                dofmt.$O\
       -        errfmt.$O\
                fltfmt.$O\
                fmt.$O\
                fmtfd.$O\
 (DIR) diff --git a/src/lib9/quote.c b/src/lib9/quote.c
       t@@ -1,9 +1,9 @@
        #include <u.h>
        #include <libc.h>
        
       -int        (*doquote)(int);
        
        /* in libfmt */
       +extern int (*doquote)(int);
        extern int __needsquotes(char*, int*);
        extern int __runeneedsquotes(Rune*, int*);
        
 (DIR) diff --git a/src/libthread/fdwait.c b/src/libthread/fdwait.c
       t@@ -4,10 +4,87 @@
        #include <thread.h>
        
        #include <errno.h>
       -#include <poll.h>
        #include <unistd.h>
        #include <fcntl.h>
        
       +#define debugpoll 0
       +
       +#ifdef __APPLE__
       +#include <sys/time.h>
       +enum { POLLIN=1, POLLOUT=2, POLLERR=4 };
       +struct pollfd
       +{
       +        int fd;
       +        int events;
       +        int revents;
       +};
       +
       +int
       +poll(struct pollfd *p, int np, int ms)
       +{
       +        int i, maxfd, n;
       +        struct timeval tv, *tvp;
       +        fd_set rfd, wfd, efd;
       +        
       +        maxfd = -1;
       +        FD_ZERO(&rfd);
       +        FD_ZERO(&wfd);
       +        FD_ZERO(&efd);
       +        for(i=0; i<np; i++){
       +                p[i].revents = 0;
       +                if(p[i].fd == -1)
       +                        continue;
       +                if(p[i].fd > maxfd)
       +                        maxfd = p[i].fd;
       +                if(p[i].events & POLLIN)
       +                        FD_SET(p[i].fd,        &rfd);
       +                if(p[i].events & POLLOUT)
       +                        FD_SET(p[i].fd, &wfd);
       +                FD_SET(p[i].fd, &efd);
       +        }
       +
       +        if(ms != -1){
       +                tv.tv_usec = (ms%1000)*1000;
       +                tv.tv_sec = ms/1000;
       +                tvp = &tv;
       +        }else
       +                tvp = nil;
       +
       +        if(debugpoll){
       +                fprint(2, "select %d:", maxfd+1);
       +                for(i=0; i<=maxfd; i++){
       +                        if(FD_ISSET(i, &rfd))
       +                                fprint(2, " r%d", i);
       +                        if(FD_ISSET(i, &wfd))
       +                                fprint(2, " w%d", i);
       +                        if(FD_ISSET(i, &efd))
       +                                fprint(2, " e%d", i);
       +                }
       +                fprint(2, "; tp=%p, t=%d.%d\n", tvp, tv.tv_sec, tv.tv_usec);
       +        }
       +
       +        n = select(maxfd+1, &rfd, &wfd, &efd, tvp);
       +
       +        if(n <= 0)
       +                return n;
       +
       +        for(i=0; i<np; i++){
       +                if(p[i].fd == -1)
       +                        continue;
       +                if(FD_ISSET(p[i].fd, &rfd))
       +                        p[i].revents |= POLLIN;
       +                if(FD_ISSET(p[i].fd, &wfd))
       +                        p[i].revents |= POLLOUT;
       +                if(FD_ISSET(p[i].fd, &efd))
       +                        p[i].revents |= POLLERR;
       +        } 
       +        return n;
       +}
       +
       +#else
       +#include <poll.h>
       +#endif
       +
        /*
         * Poll file descriptors in an idle loop.
         */
       t@@ -34,21 +111,22 @@ pollidle(void *v)
                uint now;
        
                for(;; yield()){
       -                //fprint(2, "poll %d:", npoll);
       +                if(debugpoll) fprint(2, "poll %d:", npoll);
                        for(i=0; i<npoll; i++){
       -                        //fprint(2, " %d%c", pfd[i].fd, pfd[i].events==POLLIN ? 'r' : 'w');
       +                        if(debugpoll) fprint(2, " %d%c", pfd[i].fd, pfd[i].events==POLLIN ? 'r' : 'w');
                                pfd[i].revents = 0;
                        }
                        t = -1;
       +                now = p9nsec()/1000000;
                        for(i=0; i<nsleep; i++){
       -                        now = p9nsec()/1000000;
                                n = sleeptime[i] - now;
       +                        if(debugpoll) fprint(2, " s%d", n);
                                if(n < 0)
                                        n = 0;
                                if(t == -1 || n < t)
                                        t = n;
                        }
       -                //fprint(2, "\n");
       +                if(debugpoll) fprint(2, "; t=%d\n", t);
                
                        n = poll(pfd, npoll, t);
                        //fprint(2, "poll ret %d:", n);