mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
Tweaks for the Macintosh.
This commit is contained in:
parent
6e2cec77b2
commit
53dbac9485
5 changed files with 87 additions and 9 deletions
4
bin/9c
4
bin/9c
|
@ -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" ;;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include <libc.h>
|
||||
#include <fcall.h>
|
||||
#include <thread.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
|
||||
enum
|
||||
|
|
|
@ -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\
|
||||
|
|
|
@ -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*);
|
||||
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue