aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/exec.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-12-27 18:21:58 +0000
committerrsc <devnull@localhost>2004-12-27 18:21:58 +0000
commit955a2ca78d7efc2787864e38a3d902df16fc2541 (patch)
tree2767b679277c77550c9c993debff87c4761108cd /src/libthread/exec.c
parente127e40bb1327662a05f5b70dd1bbca5c69b042c (diff)
downloadplan9port-955a2ca78d7efc2787864e38a3d902df16fc2541.tar.gz
plan9port-955a2ca78d7efc2787864e38a3d902df16fc2541.tar.bz2
plan9port-955a2ca78d7efc2787864e38a3d902df16fc2541.zip
starting to work on Linux
Diffstat (limited to 'src/libthread/exec.c')
-rw-r--r--src/libthread/exec.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/libthread/exec.c b/src/libthread/exec.c
index f31b004a..dfdb71b6 100644
--- a/src/libthread/exec.c
+++ b/src/libthread/exec.c
@@ -6,26 +6,36 @@
static Lock thewaitlock;
static Channel *thewaitchan;
-static Channel *dowaitchan;
-static Channel *execchan;
+Channel *_dowaitchan;
+Channel *_threadexecchan;
+Proc *_threadexecproc;
+QLock _threadexeclock;
+
+static void
+execthread(void *v)
+{
+ Execjob *e;
+
+ USED(v);
+ while((e = recvp(_threadexecchan)) != nil){
+print("%d doexec pid %d\n", time(0), getpid());
+ sendul(e->c, _threadspawn(e->fd, e->cmd, e->argv));
+ }
+}
static void
waitproc(void *v)
{
Channel *c;
Waitmsg *w;
- Execjob *e;
_threadsetsysproc();
+ _threadexecproc = proc();
+ threadcreate(execthread, nil, 65536);
for(;;){
- for(;;){
- while((e = nbrecvp(execchan)) != nil)
- sendul(e->c, _threadspawn(e->fd, e->cmd, e->argv));
- if((w = wait()) != nil)
- break;
+ while((w = wait()) == nil)
if(errno == ECHILD)
- recvul(dowaitchan);
- }
+ recvul(_dowaitchan);
if((c = thewaitchan) != nil)
sendp(c, w);
else
@@ -94,20 +104,20 @@ _threadspawn(int fd[3], char *cmd, char *argv[])
close(fd[1]);
if(fd[2] != fd[1] && fd[2] != fd[0])
close(fd[2]);
- channbsendul(dowaitchan, 1);
+ channbsendul(_dowaitchan, 1);
return pid;
}
int
threadspawn(int fd[3], char *cmd, char *argv[])
{
- if(dowaitchan == nil){
+ if(_dowaitchan == nil){
lock(&thewaitlock);
- if(dowaitchan == nil){
- dowaitchan = chancreate(sizeof(ulong), 1);
- chansetname(dowaitchan, "dowaitchan");
- execchan = chancreate(sizeof(void*), 0);
- chansetname(execchan, "execchan");
+ if(_dowaitchan == nil){
+ _dowaitchan = chancreate(sizeof(ulong), 1);
+ chansetname(_dowaitchan, "dowaitchan");
+ _threadexecchan = chancreate(sizeof(void*), 1);
+ chansetname(_threadexecchan, "execchan");
proccreate(waitproc, nil, STACK);
}
unlock(&thewaitlock);