diff options
author | glenda <glenda@cirno> | 2011-10-02 23:14:14 +0200 |
---|---|---|
committer | glenda <glenda@cirno> | 2011-10-02 23:14:14 +0200 |
commit | da4d5c9c2174c6890b6494d208adf36f24bdaf6e (patch) | |
tree | 1d226442fcfccbdbc725d708fbdadd345de9fd51 /sys/src/libdraw/keyboard.c | |
parent | b8d741d34b4130afabe5467a0d9e0e3d57e6c765 (diff) |
libdraw: shutdown keyboard and mouseprocs with threadint, libthread: avoid delayed note leak (this fixes the "too many delayed notes" error with auth/fgui)
Diffstat (limited to 'sys/src/libdraw/keyboard.c')
-rw-r--r-- | sys/src/libdraw/keyboard.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/sys/src/libdraw/keyboard.c b/sys/src/libdraw/keyboard.c index 5ab911ab8..9f3b29587 100644 --- a/sys/src/libdraw/keyboard.c +++ b/sys/src/libdraw/keyboard.c @@ -4,26 +4,15 @@ #include <thread.h> #include <keyboard.h> - void closekeyboard(Keyboardctl *kc) { if(kc == nil) return; - - postnote(PNPROC, kc->pid, "kill"); - -#ifdef BUG - /* Drain the channel */ - while(?kc->c) - <-kc->c; -#endif - close(kc->ctlfd); close(kc->consfd); - free(kc->file); - free(kc->c); - free(kc); + kc->consfd = kc->ctlfd = -1; + threadint(kc->pid); } static @@ -37,23 +26,23 @@ _ioproc(void *arg) kc = arg; threadsetname("kbdproc"); - kc->pid = getpid(); n = 0; - for(;;){ +loop: + while(kc->consfd >= 0){ while(n>0 && fullrune(buf, n)){ m = chartorune(&r, buf); n -= m; memmove(buf, buf+m, n); - send(kc->c, &r); - } - m = read(kc->consfd, buf+n, sizeof buf-n); - if(m <= 0){ - yield(); /* if error is due to exiting, we'll exit here */ - fprint(2, "keyboard read error: %r\n"); - threadexits("error"); + if(send(kc->c, &r) < 0) + goto loop; } + if((m = read(kc->consfd, buf+n, sizeof buf-n)) <= 0) + goto loop; n += m; } + chanfree(kc->c); + free(kc->file); + free(kc); } Keyboardctl* @@ -91,7 +80,7 @@ Error2: } free(t); kc->c = chancreate(sizeof(Rune), 20); - proccreate(_ioproc, kc, 4096); + kc->pid = proccreate(_ioproc, kc, 4096); return kc; } |