Get rid of 9proc.
This commit is contained in:
parent
040d1d02f5
commit
05d8c6df6c
9 changed files with 38 additions and 224 deletions
|
|
@ -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
|
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include "9proc.h"
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_exits(char *s)
|
_exits(char *s)
|
||||||
{
|
{
|
||||||
_p9uprocdie();
|
|
||||||
|
|
||||||
if(s && *s)
|
if(s && *s)
|
||||||
_exit(1);
|
_exit(1);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
|
|
||||||
static pthread_mutex_t initmutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t initmutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
#include <u.h>
|
#include <u.h>
|
||||||
#define NOPLAN9DEFINES
|
#define NOPLAN9DEFINES
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include "9proc.h"
|
|
||||||
|
|
||||||
extern void p9main(int, char**);
|
extern void p9main(int, char**);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
_p9uproc(0);
|
|
||||||
p9main(argc, argv);
|
p9main(argc, argv);
|
||||||
exits("main");
|
exits("main");
|
||||||
return 99;
|
return 99;
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,6 @@ LIB9OFILES=\
|
||||||
_exits.$O\
|
_exits.$O\
|
||||||
_p9dialparse.$O\
|
_p9dialparse.$O\
|
||||||
_p9dir.$O\
|
_p9dir.$O\
|
||||||
_p9proc-$SYSNAME.$O\
|
|
||||||
announce.$O\
|
announce.$O\
|
||||||
argv0.$O\
|
argv0.$O\
|
||||||
atexit.$O\
|
atexit.$O\
|
||||||
|
|
@ -99,8 +98,6 @@ LIB9OFILES=\
|
||||||
errstr.$O\
|
errstr.$O\
|
||||||
exec.$O\
|
exec.$O\
|
||||||
fcallfmt.$O\
|
fcallfmt.$O\
|
||||||
fork.$O\
|
|
||||||
ffork-$SYSNAME.$O\
|
|
||||||
get9root.$O\
|
get9root.$O\
|
||||||
getcallerpc-$OBJTYPE.$O\
|
getcallerpc-$OBJTYPE.$O\
|
||||||
getenv.$O\
|
getenv.$O\
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#define NOPLAN9DEFINES
|
#define NOPLAN9DEFINES
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include "9proc.h"
|
|
||||||
|
|
||||||
extern char *_p9sigstr(int, char*);
|
extern char *_p9sigstr(int, char*);
|
||||||
|
|
||||||
|
|
@ -41,6 +40,21 @@ static struct {
|
||||||
#endif
|
#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 (*notifyf)(void*, char*);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -48,19 +62,27 @@ notifysigf(int sig)
|
||||||
{
|
{
|
||||||
int v;
|
int v;
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
Uproc *up;
|
Jmp *j;
|
||||||
|
|
||||||
up = _p9uproc(1);
|
j = (*_notejmpbuf)();
|
||||||
v = p9setjmp(up->notejb);
|
v = p9setjmp(j->b);
|
||||||
if(v == 0 && notifyf)
|
if(v == 0 && notifyf)
|
||||||
(*notifyf)(nil, _p9sigstr(sig, tmp));
|
(*notifyf)(nil, _p9sigstr(sig, tmp));
|
||||||
else if(v == 2){
|
else if(v == 2){
|
||||||
if(0)print("HANDLED %d\n", sig);
|
if(0)print("HANDLED %d\n", sig);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(0)print("DEFAULT %d\n", sig);
|
if(0)print("DEFAULT %d\n", sig);
|
||||||
signal(sig, SIG_DFL);
|
signal(sig, SIG_DFL);
|
||||||
kill(getpid(), sig);
|
raise(sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
noted(int v)
|
||||||
|
{
|
||||||
|
p9longjmp((*_notejmpbuf)()->b, v==NCONT ? 2 : 1);
|
||||||
|
abort();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -69,7 +91,6 @@ notify(void (*f)(void*, char*))
|
||||||
int i;
|
int i;
|
||||||
struct sigaction sa, osa;
|
struct sigaction sa, osa;
|
||||||
|
|
||||||
_p9uproc(0);
|
|
||||||
memset(&sa, 0, sizeof sa);
|
memset(&sa, 0, sizeof sa);
|
||||||
if(f == 0)
|
if(f == 0)
|
||||||
sa.sa_handler = SIG_DFL;
|
sa.sa_handler = SIG_DFL;
|
||||||
|
|
@ -87,8 +108,12 @@ notify(void (*f)(void*, char*))
|
||||||
sigaction(sigs[i].sig, nil, &osa);
|
sigaction(sigs[i].sig, nil, &osa);
|
||||||
if(osa.sa_handler != SIG_DFL)
|
if(osa.sa_handler != SIG_DFL)
|
||||||
continue;
|
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)
|
if(sigs[i].restart)
|
||||||
sa.sa_flags |= SA_RESTART;
|
sa.sa_flags |= SA_RESTART;
|
||||||
else
|
else
|
||||||
|
|
@ -97,14 +122,3 @@ notify(void (*f)(void*, char*))
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
noted(int v)
|
|
||||||
{
|
|
||||||
Uproc *up;
|
|
||||||
|
|
||||||
up = _p9uproc(1);
|
|
||||||
p9longjmp(up->notejb, v==NCONT ? 2 : 1);
|
|
||||||
abort();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ post9pservice(int fd, char *name)
|
||||||
free(ns);
|
free(ns);
|
||||||
if(s == nil)
|
if(s == nil)
|
||||||
return -1;
|
return -1;
|
||||||
switch(rfork(RFPROC|RFFDG)){
|
switch(fork()){
|
||||||
case -1:
|
case -1:
|
||||||
return -1;
|
return -1;
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <libc.h>
|
#include <libc.h>
|
||||||
#include "9proc.h"
|
|
||||||
#undef rfork
|
#undef rfork
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -13,7 +12,6 @@ p9rfork(int flags)
|
||||||
int n;
|
int n;
|
||||||
char buf[128], *q;
|
char buf[128], *q;
|
||||||
|
|
||||||
_p9uproc(0);
|
|
||||||
if((flags&(RFPROC|RFFDG|RFMEM)) == (RFPROC|RFFDG)){
|
if((flags&(RFPROC|RFFDG|RFMEM)) == (RFPROC|RFFDG)){
|
||||||
/* check other flags before we commit */
|
/* check other flags before we commit */
|
||||||
flags &= ~(RFPROC|RFFDG);
|
flags &= ~(RFPROC|RFFDG);
|
||||||
|
|
@ -73,7 +71,6 @@ p9rfork(int flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_p9uproc(0);
|
|
||||||
if(pid != 0)
|
if(pid != 0)
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue