vx32

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

commit f042e1f5454c68291e03d96be8a4e2f19cbdf1b3
parent 218811d066c15fb10060f586b466d91001dcc0bb
Author: Russ Cox <rsc@swtch.com>
Date:   Sat, 28 Jun 2008 22:13:16 -0400

9vx/OSX: attempt at using pipes instead of pthread_cond_t

Diffstat:
src/9vx/a/dat.h | 3+++
src/9vx/osx/screen.c | 2++
src/9vx/osx/signal.c | 2+-
src/9vx/sched.c | 32+++++++++++++++++++++++++++++++-
4 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/9vx/a/dat.h b/src/9vx/a/dat.h @@ -356,5 +356,8 @@ struct Psleep { pthread_mutex_t mutex; pthread_cond_t cond; + int fd[2]; + vlong nread; + vlong nwrite; }; diff --git a/src/9vx/osx/screen.c b/src/9vx/osx/screen.c @@ -182,6 +182,8 @@ static Psleep scr; void screeninit(void) { +iprint("screeninit %p\n", &scr); + pinit(&scr); plock(&scr); kproc("*screen*", screenproc, nil); while(osx.window == nil) diff --git a/src/9vx/osx/signal.c b/src/9vx/osx/signal.c @@ -10,7 +10,7 @@ * See also http://lists.apple.com/archives/darwin-dev/2006/Oct/msg00122.html */ -#define __DARWIN_UNIX_03 0 +#define __DARWIN_UNIX03 0 #include <mach/mach.h> #include <sys/ucontext.h> diff --git a/src/9vx/sched.c b/src/9vx/sched.c @@ -10,6 +10,7 @@ */ #define WANT_M +#define PIPES 0 #include "u.h" #include <pthread.h> @@ -30,6 +31,8 @@ void plock(Psleep *p) { pthread_mutex_lock(&p->mutex); + if(p->fd[1] == 0) + pipe(p->fd); } void @@ -51,17 +54,36 @@ psleep(Psleep *p) * condition. This is okay because we hold the lock that * protects the condition in the first place. Sigh. */ +#if PIPES + p->nread++; + punlock(p); + char c; + read(p->fd[0], &c, 1); + plock(p); +#else pthread_cond_init(&p->cond, nil); pthread_cond_wait(&p->cond, &p->mutex); +#endif } void pwakeup(Psleep *p) { +#if PIPES + char c = 0; + int nbad = 0; + if(p->nwrite < p->nread){ + p->nwrite++; + while(write(p->fd[1], &c, 1) < 1){ + if(++nbad%100 == 0) + iprint("pwakeup: write keeps failing\n"); + } + } +#else pthread_cond_signal(&p->cond); +#endif } - /* * The cpu0 scheduler calls idlehands when there is * nothing left on the main runqueue (runproc @@ -178,3 +200,11 @@ runproc(void) return p; } +void +schedinit0(void) +{ + pinit(&run); + pinit(&idling); +iprint("pinit\n"); +} +