shuffle to allow use of execchan in non-pthreads impls
This commit is contained in:
parent
e8a7b96999
commit
e127e40bb1
3 changed files with 43 additions and 6 deletions
|
|
@ -7,17 +7,22 @@
|
|||
static Lock thewaitlock;
|
||||
static Channel *thewaitchan;
|
||||
static Channel *dowaitchan;
|
||||
static Channel *execchan;
|
||||
|
||||
/* BUG - start waitproc on first exec, not when threadwaitchan is called */
|
||||
static void
|
||||
waitproc(void *v)
|
||||
{
|
||||
Channel *c;
|
||||
Waitmsg *w;
|
||||
Execjob *e;
|
||||
|
||||
_threadsetsysproc();
|
||||
for(;;){
|
||||
while((w = wait()) == nil){
|
||||
for(;;){
|
||||
while((e = nbrecvp(execchan)) != nil)
|
||||
sendul(e->c, _threadspawn(e->fd, e->cmd, e->argv));
|
||||
if((w = wait()) != nil)
|
||||
break;
|
||||
if(errno == ECHILD)
|
||||
recvul(dowaitchan);
|
||||
}
|
||||
|
|
@ -40,15 +45,12 @@ threadwaitchan(void)
|
|||
}
|
||||
thewaitchan = chancreate(sizeof(Waitmsg*), 4);
|
||||
chansetname(thewaitchan, "threadwaitchan");
|
||||
dowaitchan = chancreate(sizeof(ulong), 1);
|
||||
chansetname(dowaitchan, "dowaitchan");
|
||||
proccreate(waitproc, nil, STACK);
|
||||
unlock(&thewaitlock);
|
||||
return thewaitchan;
|
||||
}
|
||||
|
||||
int
|
||||
threadspawn(int fd[3], char *cmd, char *argv[])
|
||||
_threadspawn(int fd[3], char *cmd, char *argv[])
|
||||
{
|
||||
int i, n, p[2], pid;
|
||||
char exitstr[100];
|
||||
|
|
@ -96,6 +98,24 @@ threadspawn(int fd[3], char *cmd, char *argv[])
|
|||
return pid;
|
||||
}
|
||||
|
||||
int
|
||||
threadspawn(int fd[3], char *cmd, char *argv[])
|
||||
{
|
||||
if(dowaitchan == nil){
|
||||
lock(&thewaitlock);
|
||||
if(dowaitchan == nil){
|
||||
dowaitchan = chancreate(sizeof(ulong), 1);
|
||||
chansetname(dowaitchan, "dowaitchan");
|
||||
execchan = chancreate(sizeof(void*), 0);
|
||||
chansetname(execchan, "execchan");
|
||||
proccreate(waitproc, nil, STACK);
|
||||
}
|
||||
unlock(&thewaitlock);
|
||||
}
|
||||
return _runthreadspawn(fd, cmd, argv);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
_threadexec(Channel *cpid, int fd[3], char *cmd, char *argv[])
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue