Get rid of 9proc.

This commit is contained in:
rsc 2004-09-23 03:06:04 +00:00
parent 040d1d02f5
commit 05d8c6df6c
9 changed files with 38 additions and 224 deletions

View file

@ -1,23 +0,0 @@
#ifndef _9PROC_H_
#define _9PROC_H_ 1
enum
{
NPRIV = 16,
RENDHASH = 33,
};
typedef struct Uproc Uproc;
struct Uproc
{
int pid;
int state;
void *priv[NPRIV];
p9jmp_buf notejb;
};
extern Uproc *_p9uproc(int);
extern void _p9uprocdie(void);
extern void _clearuproc(void);
#endif

View file

@ -1,12 +1,9 @@
#include <u.h>
#include <libc.h>
#include "9proc.h"
void
_exits(char *s)
{
_p9uprocdie();
if(s && *s)
_exit(1);
_exit(0);

View file

@ -2,6 +2,7 @@
#include <unistd.h>
#include <sys/time.h>
#include <sched.h>
#include <errno.h>
#include <libc.h>
static pthread_mutex_t initmutex = PTHREAD_MUTEX_INITIALIZER;

View file

@ -1,14 +1,12 @@
#include <u.h>
#define NOPLAN9DEFINES
#include <libc.h>
#include "9proc.h"
extern void p9main(int, char**);
int
main(int argc, char **argv)
{
_p9uproc(0);
p9main(argc, argv);
exits("main");
return 99;

View file

@ -67,7 +67,6 @@ LIB9OFILES=\
_exits.$O\
_p9dialparse.$O\
_p9dir.$O\
_p9proc-$SYSNAME.$O\
announce.$O\
argv0.$O\
atexit.$O\
@ -99,8 +98,6 @@ LIB9OFILES=\
errstr.$O\
exec.$O\
fcallfmt.$O\
fork.$O\
ffork-$SYSNAME.$O\
get9root.$O\
getcallerpc-$OBJTYPE.$O\
getenv.$O\

View file

@ -2,7 +2,6 @@
#include <signal.h>
#define NOPLAN9DEFINES
#include <libc.h>
#include "9proc.h"
extern char *_p9sigstr(int, char*);
@ -41,6 +40,21 @@ static struct {
#endif
};
typedef struct Jmp Jmp;
struct Jmp
{
p9jmp_buf b;
};
static Jmp onejmp;
static Jmp*
getonejmp(void)
{
return &onejmp;
}
Jmp *(*_notejmpbuf)(void) = getonejmp;
static void (*notifyf)(void*, char*);
static void
@ -48,28 +62,35 @@ notifysigf(int sig)
{
int v;
char tmp[64];
Uproc *up;
Jmp *j;
up = _p9uproc(1);
v = p9setjmp(up->notejb);
j = (*_notejmpbuf)();
v = p9setjmp(j->b);
if(v == 0 && notifyf)
(*notifyf)(nil, _p9sigstr(sig, tmp));
else if(v == 2){
if(0)print("HANDLED %d\n", sig);
if(0)print("HANDLED %d\n", sig);
return;
}
if(0)print("DEFAULT %d\n", sig);
if(0)print("DEFAULT %d\n", sig);
signal(sig, SIG_DFL);
kill(getpid(), sig);
raise(sig);
}
int
noted(int v)
{
p9longjmp((*_notejmpbuf)()->b, v==NCONT ? 2 : 1);
abort();
return 0;
}
int
notify(void (*f)(void*, char*))
{
int i;
struct sigaction sa, osa;
_p9uproc(0);
memset(&sa, 0, sizeof sa);
if(f == 0)
sa.sa_handler = SIG_DFL;
@ -87,8 +108,12 @@ notify(void (*f)(void*, char*))
sigaction(sigs[i].sig, nil, &osa);
if(osa.sa_handler != SIG_DFL)
continue;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, i);
/*
* We assume that one jump buffer per thread
* is okay, which means that we can't deal with
* signal handlers called during signal handlers.
*/
sigfillset(&sa.sa_mask);
if(sigs[i].restart)
sa.sa_flags |= SA_RESTART;
else
@ -97,14 +122,3 @@ notify(void (*f)(void*, char*))
}
return 0;
}
int
noted(int v)
{
Uproc *up;
up = _p9uproc(1);
p9longjmp(up->notejb, v==NCONT ? 2 : 1);
abort();
return 0;
}

View file

@ -14,7 +14,7 @@ post9pservice(int fd, char *name)
free(ns);
if(s == nil)
return -1;
switch(rfork(RFPROC|RFFDG)){
switch(fork()){
case -1:
return -1;
case 0:

View file

@ -1,167 +0,0 @@
/*
NAME
rendezvous - user level process synchronization
SYNOPSIS
ulong rendezvous(ulong tag, ulong value)
DESCRIPTION
The rendezvous system call allows two processes to synchro-
nize and exchange a value. In conjunction with the shared
memory system calls (see segattach(2) and fork(2)), it
enables parallel programs to control their scheduling.
Two processes wishing to synchronize call rendezvous with a
common tag, typically an address in memory they share. One
process will arrive at the rendezvous first; it suspends
execution until a second arrives. When a second process
meets the rendezvous the value arguments are exchanged
between the processes and returned as the result of the
respective rendezvous system calls. Both processes are
awakened when the rendezvous succeeds.
The set of tag values which two processes may use to
rendezvous-their tag space-is inherited when a process
forks, unless RFREND is set in the argument to rfork; see
fork(2).
If a rendezvous is interrupted the return value is ~0, so
that value should not be used in normal communication.
* This simulates rendezvous with shared memory, pause, and SIGUSR1.
*/
#include <u.h>
typedef u32int u32;
#include <errno.h>
#include <sys/time.h>
#define __user
#include <linux/linkage.h>
#include <linux/futex.h>
#include <libc.h>
enum
{
VOUSHASH = 257,
};
typedef struct Vous Vous;
struct Vous
{
Vous *link;
Lock lk;
int pid;
ulong val;
ulong tag;
};
static Vous vouspool[2048];
static int nvousused;
static Vous *vousfree;
static Vous *voushash[VOUSHASH];
static Lock vouslock;
static Vous*
getvous(void)
{
Vous *v;
if(vousfree){
v = vousfree;
vousfree = v->link;
}else if(nvousused < nelem(vouspool))
v = &vouspool[nvousused++];
else
abort();
return v;
}
static void
putvous(Vous *v)
{
lock(&vouslock);
v->link = vousfree;
vousfree = v;
unlock(&vouslock);
}
static Vous*
findvous(ulong tag, ulong val, int pid)
{
int h;
Vous *v, **l;
lock(&vouslock);
h = tag%VOUSHASH;
for(l=&voushash[h], v=*l; v; l=&(*l)->link, v=*l){
if(v->tag == tag){
*l = v->link;
unlock(&vouslock);
return v;
}
}
v = getvous();
v->pid = pid;
v->link = voushash[h];
v->val = val;
v->tag = tag;
lock(&v->lk);
voushash[h] = v;
unlock(&vouslock);
return v;
}
#define DBG 0
ulong
rendezvous(ulong tag, ulong val)
{
int me, vpid;
ulong rval;
Vous *v;
me = getpid();
v = findvous(tag, val, me);
if(v->pid == me){
if(DBG)fprint(2, "pid is %d tag %lux, sleeping\n", me, tag);
/*
* No rendezvous partner was found; the next guy
* through will find v and wake us, so we must go
* to sleep.
*
* To go to sleep:
* 1. disable USR1 signals.
* 2. unlock v->lk (tells waker okay to signal us).
* 3. atomically suspend and enable USR1 signals.
*
* The call to ignusr1() could be done once at
* process creation instead of every time through rendezvous.
*/
v->val = val;
unlock(&v->lk);
while(sys_futex((u32int*)&v->tag, FUTEX_WAIT, tag, nil, nil) < 0 && errno==EINTR)
;
rval = v->val;
if(DBG)fprint(2, "pid is %d, awake\n", me);
putvous(v);
}else{
/*
* Found someone to meet. Wake him:
*
* A. lock v->lk (waits for him to get to his step 2)
* B. send a USR1
*
* He won't get the USR1 until he suspends, which
* means it must wake him up (it can't get delivered
* before he sleeps).
*/
vpid = v->pid;
lock(&v->lk);
rval = v->val;
v->val = val;
v->tag++;
unlock(&v->lk);
sys_futex((u32int*)&v->tag, FUTEX_WAKE, 1, nil, nil);
}
return rval;
}

View file

@ -2,7 +2,6 @@
#include <sys/wait.h>
#include <signal.h>
#include <libc.h>
#include "9proc.h"
#undef rfork
int
@ -13,7 +12,6 @@ p9rfork(int flags)
int n;
char buf[128], *q;
_p9uproc(0);
if((flags&(RFPROC|RFFDG|RFMEM)) == (RFPROC|RFFDG)){
/* check other flags before we commit */
flags &= ~(RFPROC|RFFDG);
@ -73,7 +71,6 @@ p9rfork(int flags)
}
}
}
_p9uproc(0);
if(pid != 0)
return pid;
}