fixed
This commit is contained in:
parent
201e19d672
commit
880ab2f10a
4 changed files with 32 additions and 4 deletions
|
|
@ -25,6 +25,10 @@ struct Event
|
||||||
|
|
||||||
struct Window
|
struct Window
|
||||||
{
|
{
|
||||||
|
/* coordinate wineventproc and window thread */
|
||||||
|
QLock lk;
|
||||||
|
int ref;
|
||||||
|
|
||||||
/* file descriptors */
|
/* file descriptors */
|
||||||
CFid* ctl;
|
CFid* ctl;
|
||||||
CFid* event;
|
CFid* event;
|
||||||
|
|
@ -112,6 +116,8 @@ extern int winsetaddr(Window*, char*, int);
|
||||||
extern char* winreadbody(Window*, int*);
|
extern char* winreadbody(Window*, int*);
|
||||||
extern void windormant(Window*);
|
extern void windormant(Window*);
|
||||||
extern void winsetdump(Window*, char*, char*);
|
extern void winsetdump(Window*, char*, char*);
|
||||||
|
extern void winincref(Window*);
|
||||||
|
extern void windecref(Window*);
|
||||||
|
|
||||||
extern void readmbox(Message*, char*, char*);
|
extern void readmbox(Message*, char*, char*);
|
||||||
extern void rewritembox(Window*, Message*);
|
extern void rewritembox(Window*, Message*);
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,7 @@ mainctl(void *v)
|
||||||
char *s, *t, *buf;
|
char *s, *t, *buf;
|
||||||
|
|
||||||
w = v;
|
w = v;
|
||||||
|
winincref(w);
|
||||||
proccreate(wineventproc, w, STACK);
|
proccreate(wineventproc, w, STACK);
|
||||||
|
|
||||||
for(;;){
|
for(;;){
|
||||||
|
|
|
||||||
|
|
@ -720,8 +720,7 @@ mesgcommand(Message *m, char *cmd)
|
||||||
}
|
}
|
||||||
if(strcmp(args[0], "Del") == 0){
|
if(strcmp(args[0], "Del") == 0){
|
||||||
if(windel(m->w, 0)){
|
if(windel(m->w, 0)){
|
||||||
chanfree(m->w->cevent);
|
windecref(m->w);
|
||||||
free(m->w);
|
|
||||||
m->w = nil;
|
m->w = nil;
|
||||||
if(m->isreply)
|
if(m->isreply)
|
||||||
delreply(m);
|
delreply(m);
|
||||||
|
|
@ -886,6 +885,7 @@ mesgctl(void *v)
|
||||||
m = v;
|
m = v;
|
||||||
w = m->w;
|
w = m->w;
|
||||||
threadsetname("mesgctl");
|
threadsetname("mesgctl");
|
||||||
|
winincref(w);
|
||||||
proccreate(wineventproc, w, STACK);
|
proccreate(wineventproc, w, STACK);
|
||||||
for(;;){
|
for(;;){
|
||||||
e = recvp(w->cevent);
|
e = recvp(w->cevent);
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,31 @@ newwindow(void)
|
||||||
w->body = nil;
|
w->body = nil;
|
||||||
w->data = nil;
|
w->data = nil;
|
||||||
w->cevent = chancreate(sizeof(Event*), 0);
|
w->cevent = chancreate(sizeof(Event*), 0);
|
||||||
|
w->ref = 1;
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
winincref(Window *w)
|
||||||
|
{
|
||||||
|
qlock(&w->lk);
|
||||||
|
++w->ref;
|
||||||
|
qunlock(&w->lk);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
windecref(Window *w)
|
||||||
|
{
|
||||||
|
qlock(&w->lk);
|
||||||
|
if(--w->ref > 0){
|
||||||
|
qunlock(&w->lk);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fsclose(w->event);
|
||||||
|
chanfree(w->cevent);
|
||||||
|
free(w);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
winsetdump(Window *w, char *dir, char *cmd)
|
winsetdump(Window *w, char *dir, char *cmd)
|
||||||
{
|
{
|
||||||
|
|
@ -125,6 +147,7 @@ wingetec(Window *w)
|
||||||
w->nbuf = fsread(w->event, w->buf, sizeof w->buf);
|
w->nbuf = fsread(w->event, w->buf, sizeof w->buf);
|
||||||
if(w->nbuf <= 0){
|
if(w->nbuf <= 0){
|
||||||
/* probably because window has exited, and only called by wineventproc, so just shut down */
|
/* probably because window has exited, and only called by wineventproc, so just shut down */
|
||||||
|
windecref(w);
|
||||||
threadexits(nil);
|
threadexits(nil);
|
||||||
}
|
}
|
||||||
w->bufp = w->buf;
|
w->bufp = w->buf;
|
||||||
|
|
@ -255,8 +278,6 @@ windel(Window *w, int sure)
|
||||||
windormant(w);
|
windormant(w);
|
||||||
fsclose(w->ctl);
|
fsclose(w->ctl);
|
||||||
w->ctl = nil;
|
w->ctl = nil;
|
||||||
fsclose(w->event);
|
|
||||||
w->event = nil;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue