vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

commit a6f16f2f73874054262169792554292d7bcce3cb
parent 5bd8ac0c45b2fcbe0d8d536693129823559c2a16
Author: Russ Cox <rsc@swtch.com>
Date:   Sat, 28 Jun 2008 22:26:40 -0400

9vx/OSX: working pipe code for sleep/wakeup

Diffstat:
src/9vx/main.c | 2+-
src/9vx/sched.c | 15++++++++++++---
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/9vx/main.c b/src/9vx/main.c @@ -64,7 +64,7 @@ usage(void) exit(1); } -static void +void nop(void) { } diff --git a/src/9vx/sched.c b/src/9vx/sched.c @@ -10,10 +10,11 @@ */ #define WANT_M -#define PIPES 0 +#define PIPES 1 #include "u.h" #include <pthread.h> +#include <sys/poll.h> #include <sched.h> #include "lib.h" #include "mem.h" @@ -31,8 +32,10 @@ void plock(Psleep *p) { pthread_mutex_lock(&p->mutex); - if(p->fd[1] == 0) + if(p->fd[1] == 0){ pipe(p->fd); + fcntl(p->fd[0], F_SETFL, fcntl(p->fd[0], F_GETFL)|O_NONBLOCK); + } } void @@ -58,7 +61,13 @@ psleep(Psleep *p) p->nread++; punlock(p); char c; - read(p->fd[0], &c, 1); + while(read(p->fd[0], &c, 1) < 1){ + struct pollfd pfd; + pfd.fd = p->fd[0]; + pfd.events = POLLIN; + pfd.revents = 0; + poll(&pfd, 1, 1000); + } plock(p); #else pthread_cond_init(&p->cond, nil);