mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-27 11:52:03 +00:00
change to use new thread library
This commit is contained in:
parent
0a839b8314
commit
334cb1e91c
7 changed files with 41 additions and 24 deletions
|
@ -41,6 +41,7 @@ char *fontnames[2] =
|
||||||
|
|
||||||
Command *command;
|
Command *command;
|
||||||
|
|
||||||
|
void shutdownthread(void*);
|
||||||
void acmeerrorinit(void);
|
void acmeerrorinit(void);
|
||||||
void readfile(Column*, char*);
|
void readfile(Column*, char*);
|
||||||
static int shutdown(void*, char*);
|
static int shutdown(void*, char*);
|
||||||
|
@ -167,14 +168,23 @@ threadmain(int argc, char *argv[])
|
||||||
|
|
||||||
cwait = threadwaitchan();
|
cwait = threadwaitchan();
|
||||||
ccommand = chancreate(sizeof(Command**), 0);
|
ccommand = chancreate(sizeof(Command**), 0);
|
||||||
|
chansetname(ccommand, "ccommand");
|
||||||
ckill = chancreate(sizeof(Rune*), 0);
|
ckill = chancreate(sizeof(Rune*), 0);
|
||||||
|
chansetname(ckill, "ckill");
|
||||||
cxfidalloc = chancreate(sizeof(Xfid*), 0);
|
cxfidalloc = chancreate(sizeof(Xfid*), 0);
|
||||||
|
chansetname(cxfidalloc, "cxfidalloc");
|
||||||
cxfidfree = chancreate(sizeof(Xfid*), 0);
|
cxfidfree = chancreate(sizeof(Xfid*), 0);
|
||||||
|
chansetname(cxfidfree, "cxfidfree");
|
||||||
cnewwindow = chancreate(sizeof(Channel*), 0);
|
cnewwindow = chancreate(sizeof(Channel*), 0);
|
||||||
|
chansetname(cnewwindow, "cnewwindow");
|
||||||
cerr = chancreate(sizeof(char*), 0);
|
cerr = chancreate(sizeof(char*), 0);
|
||||||
|
chansetname(cerr, "cerr");
|
||||||
cedit = chancreate(sizeof(int), 0);
|
cedit = chancreate(sizeof(int), 0);
|
||||||
|
chansetname(cedit, "cedit");
|
||||||
cexit = chancreate(sizeof(int), 0);
|
cexit = chancreate(sizeof(int), 0);
|
||||||
|
chansetname(cexit, "cexit");
|
||||||
cwarn = chancreate(sizeof(void*), 1);
|
cwarn = chancreate(sizeof(void*), 1);
|
||||||
|
chansetname(cwarn, "cwarn");
|
||||||
if(cwait==nil || ccommand==nil || ckill==nil || cxfidalloc==nil || cxfidfree==nil || cerr==nil || cexit==nil || cwarn==nil){
|
if(cwait==nil || ccommand==nil || ckill==nil || cxfidalloc==nil || cxfidfree==nil || cerr==nil || cexit==nil || cwarn==nil){
|
||||||
fprint(2, "acme: can't create initial channels: %r\n");
|
fprint(2, "acme: can't create initial channels: %r\n");
|
||||||
exits("channels");
|
exits("channels");
|
||||||
|
@ -248,8 +258,8 @@ threadmain(int argc, char *argv[])
|
||||||
threadcreate(waitthread, nil, STACK);
|
threadcreate(waitthread, nil, STACK);
|
||||||
threadcreate(xfidallocthread, nil, STACK);
|
threadcreate(xfidallocthread, nil, STACK);
|
||||||
threadcreate(newwindowthread, nil, STACK);
|
threadcreate(newwindowthread, nil, STACK);
|
||||||
|
/* threadcreate(shutdownthread, nil, STACK); */
|
||||||
threadnotify(shutdown, 1);
|
/* threadnotify(shutdown, 1); */
|
||||||
recvul(cexit);
|
recvul(cexit);
|
||||||
killprocs();
|
killprocs();
|
||||||
threadexitsall(nil);
|
threadexitsall(nil);
|
||||||
|
@ -307,6 +317,21 @@ shutdown(void *v, char *msg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void
|
||||||
|
shutdownthread(void *v)
|
||||||
|
{
|
||||||
|
char *msg;
|
||||||
|
Channel *c;
|
||||||
|
|
||||||
|
USED(v);
|
||||||
|
|
||||||
|
c = threadnotechan();
|
||||||
|
while((msg = recvp(c)) != nil)
|
||||||
|
shutdown(nil, msg);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
killprocs(void)
|
killprocs(void)
|
||||||
{
|
{
|
||||||
|
@ -332,7 +357,7 @@ acmeerrorproc(void *v)
|
||||||
USED(v);
|
USED(v);
|
||||||
threadsetname("acmeerrorproc");
|
threadsetname("acmeerrorproc");
|
||||||
buf = emalloc(8192+1);
|
buf = emalloc(8192+1);
|
||||||
while((n=threadread(errorfd, buf, 8192)) >= 0){
|
while((n=read(errorfd, buf, 8192)) >= 0){
|
||||||
buf[n] = '\0';
|
buf[n] = '\0';
|
||||||
sendp(cerr, estrdup(buf));
|
sendp(cerr, estrdup(buf));
|
||||||
}
|
}
|
||||||
|
@ -367,7 +392,7 @@ acmeerrorinit(void)
|
||||||
errorfd = pfd[1];
|
errorfd = pfd[1];
|
||||||
if(errorfd < 0)
|
if(errorfd < 0)
|
||||||
error("can't re-open acmeerror file");
|
error("can't re-open acmeerror file");
|
||||||
threadcreate(acmeerrorproc, nil, STACK);
|
proccreate(acmeerrorproc, nil, STACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -648,21 +673,6 @@ waitthread(void *v)
|
||||||
alts[WCmd].op = CHANRCV;
|
alts[WCmd].op = CHANRCV;
|
||||||
alts[NWALT].op = CHANEND;
|
alts[NWALT].op = CHANEND;
|
||||||
|
|
||||||
/*
|
|
||||||
* BUG. Actually there's no bug here but this is the
|
|
||||||
* first place you'd look. When a program is run,
|
|
||||||
* it doesn't disappear from the main tag until the
|
|
||||||
* mouse is moved or keyboard is hit. This would
|
|
||||||
* suggest that the WWait case isn't working right,
|
|
||||||
* but what's actually going on is that the X11 code
|
|
||||||
* is running a select-based threading loop that
|
|
||||||
* doesn't get interrupted until there is data from X11.
|
|
||||||
* This was done to make acme work on Suns and
|
|
||||||
* other systems where our threading was sub-par.
|
|
||||||
* Now that we've gotten pthreads working (sort of),
|
|
||||||
* we might be able to fix this properly.
|
|
||||||
* But the bug is in libdraw and libthread, not here.
|
|
||||||
*/
|
|
||||||
command = nil;
|
command = nil;
|
||||||
for(;;){
|
for(;;){
|
||||||
switch(alt(alts)){
|
switch(alt(alts)){
|
||||||
|
@ -719,7 +729,7 @@ waitthread(void *v)
|
||||||
textsetselect(t, 0, 0);
|
textsetselect(t, 0, 0);
|
||||||
}
|
}
|
||||||
if(w->msg[0])
|
if(w->msg[0])
|
||||||
warning(c->md, "%S: %s\n", c->name, w->msg);
|
warning(c->md, "%.*S: exit %s\n", c->nname-1, c->name, w->msg);
|
||||||
flushimage(display, 1);
|
flushimage(display, 1);
|
||||||
}
|
}
|
||||||
qunlock(&row.lk);
|
qunlock(&row.lk);
|
||||||
|
@ -791,6 +801,7 @@ xfidallocthread(void *v)
|
||||||
else{
|
else{
|
||||||
x = emalloc(sizeof(Xfid));
|
x = emalloc(sizeof(Xfid));
|
||||||
x->c = chancreate(sizeof(void(*)(Xfid*)), 0);
|
x->c = chancreate(sizeof(void(*)(Xfid*)), 0);
|
||||||
|
chansetname(x->c, "xc%p", x->c);
|
||||||
x->arg = x;
|
x->arg = x;
|
||||||
threadcreate(xfidctl, x->arg, STACK);
|
threadcreate(xfidctl, x->arg, STACK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,6 +178,7 @@ editcmd(Text *ct, Rune *r, uint n)
|
||||||
resetxec();
|
resetxec();
|
||||||
if(editerrc == nil){
|
if(editerrc == nil){
|
||||||
editerrc = chancreate(sizeof(char*), 0);
|
editerrc = chancreate(sizeof(char*), 0);
|
||||||
|
chansetname(editerrc, "editerrc");
|
||||||
lastpat = allocstring(0);
|
lastpat = allocstring(0);
|
||||||
}
|
}
|
||||||
threadcreate(editthread, nil, STACK);
|
threadcreate(editthread, nil, STACK);
|
||||||
|
|
|
@ -1585,6 +1585,7 @@ run(Window *win, char *s, Rune *rdir, int ndir, int newns, char *argaddr, char *
|
||||||
arg = emalloc(10*sizeof(void*));
|
arg = emalloc(10*sizeof(void*));
|
||||||
c = emalloc(sizeof *c);
|
c = emalloc(sizeof *c);
|
||||||
cpid = chancreate(sizeof(ulong), 0);
|
cpid = chancreate(sizeof(ulong), 0);
|
||||||
|
chansetname(cpid, "cpid %s", s);
|
||||||
arg[0] = win;
|
arg[0] = win;
|
||||||
arg[1] = s;
|
arg[1] = s;
|
||||||
arg[2] = rdir;
|
arg[2] = rdir;
|
||||||
|
|
|
@ -126,7 +126,7 @@ fsysinit(void)
|
||||||
fmtinstall('F', fcallfmt);
|
fmtinstall('F', fcallfmt);
|
||||||
if((u = getuser()) != nil)
|
if((u = getuser()) != nil)
|
||||||
user = estrdup(u);
|
user = estrdup(u);
|
||||||
threadcreate(fsysproc, nil, STACK);
|
proccreate(fsysproc, nil, STACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -142,7 +142,7 @@ fsysproc(void *v)
|
||||||
x = nil;
|
x = nil;
|
||||||
for(;;){
|
for(;;){
|
||||||
buf = emalloc(messagesize+UTFmax); /* overflow for appending partial rune in xfidwrite */
|
buf = emalloc(messagesize+UTFmax); /* overflow for appending partial rune in xfidwrite */
|
||||||
n = threadread9pmsg(sfd, buf, messagesize);
|
n = read9pmsg(sfd, buf, messagesize);
|
||||||
if(n <= 0){
|
if(n <= 0){
|
||||||
if(closing)
|
if(closing)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -45,6 +45,7 @@ startplumbing(void)
|
||||||
fprint(2, "acme: can't initialize plumber: %r\n");
|
fprint(2, "acme: can't initialize plumber: %r\n");
|
||||||
else{
|
else{
|
||||||
cplumb = chancreate(sizeof(Plumbmsg*), 0);
|
cplumb = chancreate(sizeof(Plumbmsg*), 0);
|
||||||
|
chansetname(cplumb, "cplumb");
|
||||||
threadcreate(plumbproc, nil, STACK);
|
threadcreate(plumbproc, nil, STACK);
|
||||||
}
|
}
|
||||||
plumbsendfid = plumbopenfid("send", OWRITE|OCEXEC);
|
plumbsendfid = plumbopenfid("send", OWRITE|OCEXEC);
|
||||||
|
|
|
@ -128,6 +128,7 @@ void
|
||||||
rxinit(void)
|
rxinit(void)
|
||||||
{
|
{
|
||||||
rechan = chancreate(sizeof(Inst*), 0);
|
rechan = chancreate(sizeof(Inst*), 0);
|
||||||
|
chansetname(rechan, "rechan");
|
||||||
lastregexp = runemalloc(1);
|
lastregexp = runemalloc(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ timerproc(void *v)
|
||||||
nt = 0;
|
nt = 0;
|
||||||
old = msec();
|
old = msec();
|
||||||
for(;;){
|
for(;;){
|
||||||
threadsleep(1); /* will sleep minimum incr */
|
sleep(1); /* will sleep minimum incr */
|
||||||
new = msec();
|
new = msec();
|
||||||
dt = new-old;
|
dt = new-old;
|
||||||
old = new;
|
old = new;
|
||||||
|
@ -98,7 +98,8 @@ void
|
||||||
timerinit(void)
|
timerinit(void)
|
||||||
{
|
{
|
||||||
ctimer = chancreate(sizeof(Timer*), 100);
|
ctimer = chancreate(sizeof(Timer*), 100);
|
||||||
threadcreate(timerproc, nil, STACK);
|
chansetname(ctimer, "ctimer");
|
||||||
|
proccreate(timerproc, nil, STACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer*
|
Timer*
|
||||||
|
@ -112,6 +113,7 @@ timerstart(int dt)
|
||||||
else{
|
else{
|
||||||
t = emalloc(sizeof(Timer));
|
t = emalloc(sizeof(Timer));
|
||||||
t->c = chancreate(sizeof(int), 0);
|
t->c = chancreate(sizeof(int), 0);
|
||||||
|
chansetname(t->c, "tc%p", t->c);
|
||||||
}
|
}
|
||||||
t->next = nil;
|
t->next = nil;
|
||||||
t->dt = dt;
|
t->dt = dt;
|
||||||
|
|
Loading…
Reference in a new issue