mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
do threading right
This commit is contained in:
parent
b10db40d3b
commit
f4b26b64bc
2 changed files with 4 additions and 26 deletions
|
@ -199,7 +199,7 @@ startfsys(void)
|
||||||
if(post9pservice(p[1], "plumb") < 0)
|
if(post9pservice(p[1], "plumb") < 0)
|
||||||
sysfatal("post9pservice plumb: %r");
|
sysfatal("post9pservice plumb: %r");
|
||||||
close(p[1]);
|
close(p[1]);
|
||||||
fsysproc(nil);
|
proccreate(fsysproc, nil, Stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -25,36 +25,18 @@ makeports(Ruleset *rules[])
|
||||||
addport(rules[i]->port);
|
addport(rules[i]->port);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
mainproc(void *v)
|
|
||||||
{
|
|
||||||
Channel *c;
|
|
||||||
|
|
||||||
c = v;
|
|
||||||
printerrors = 0;
|
|
||||||
makeports(rules);
|
|
||||||
startfsys();
|
|
||||||
sendp(c, nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
threadmain(int argc, char *argv[])
|
threadmain(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
int fd;
|
int fd;
|
||||||
int volatile dofork;
|
|
||||||
Channel *c;
|
|
||||||
|
|
||||||
progname = "plumber";
|
progname = "plumber";
|
||||||
dofork = 1;
|
|
||||||
|
|
||||||
ARGBEGIN{
|
ARGBEGIN{
|
||||||
case 'd':
|
case 'd':
|
||||||
debug = 1;
|
debug = 1;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
|
||||||
dofork = 0;
|
|
||||||
break;
|
|
||||||
case 'p':
|
case 'p':
|
||||||
plumbfile = ARGF();
|
plumbfile = ARGF();
|
||||||
break;
|
break;
|
||||||
|
@ -83,17 +65,13 @@ threadmain(int argc, char *argv[])
|
||||||
rules = readrules(plumbfile, fd);
|
rules = readrules(plumbfile, fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if(dofork)
|
|
||||||
threaddaemonize();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start all processes and threads from other proc
|
* Start all processes and threads from other proc
|
||||||
* so we (main pid) can return to user.
|
* so we (main pid) can return to user.
|
||||||
*/
|
*/
|
||||||
c = chancreate(sizeof(void*), 0);
|
printerrors = 0;
|
||||||
proccreate(mainproc, c, 8192);
|
makeports(rules);
|
||||||
recvp(c);
|
startfsys();
|
||||||
chanfree(c);
|
|
||||||
threadexits(nil);
|
threadexits(nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue