summaryrefslogtreecommitdiff
path: root/sys/src/libdraw
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-11-18 03:37:04 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2018-11-18 03:37:04 +0100
commit064ea89caa3d8b2183ad5827ee124c1213286e0c (patch)
tree830276827da9ff784d8253d5679a9fc5e2b32e00 /sys/src/libdraw
parenta25418fddcf958c8a585779c7642bb88ceaf3f66 (diff)
libdraw: avoid deadlock for mouse ioproc sending on resizec
a deadlock has been observed with samterm (thanks burnzez), that shows the mouse ioproc being stuck in sending on the resize channel, while the mouse consumer is stuck in a readmouse() loop wanting a rectangle to be drawn by the user: recv(v=0x42df50)+0x28 /sys/src/libthread/channel.c:321 readmouse(mc=0x42df50)+0x54 /sys/src/libdraw/mouse.c:34 getrect(.ret=0x41bce0,but=0x4,mc=0x42df50)+0x62 /sys/src/libdraw/getrect.c:49 r=0x41bc70 rc=0x41bc70 getr(rp=0x41bce0)+0x24 /sys/src/cmd/samterm/main.c:244 p=0x6b000004f6 r=0x2 sweeptext(new=0x0,tag=0x2d)+0x12 /sys/src/cmd/samterm/menu.c:208 r=0x2 t=0x42df50 inmesg(type=0x2,count=0x2)+0x1ab /sys/src/cmd/samterm/mesg.c:136 m=0x10000002d l=0x2d00001b00 i=0x43829000000001 t=0x438290 lp=0x42e050 rcv()+0x7a /sys/src/cmd/samterm/mesg.c:77 threadmain(argv=0x7ffffeffef90)+0x173 /sys/src/cmd/samterm/main.c:63 so avoid blocking in the mouse ioproc by using nbsend() instead of send() for writing to the resize channel.
Diffstat (limited to 'sys/src/libdraw')
-rw-r--r--sys/src/libdraw/mouse.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/src/libdraw/mouse.c b/sys/src/libdraw/mouse.c
index 984ae3350..3ae6d5cc7 100644
--- a/sys/src/libdraw/mouse.c
+++ b/sys/src/libdraw/mouse.c
@@ -66,7 +66,7 @@ _ioproc(void *arg)
switch(buf[0]){
case 'r':
one = 1;
- if(send(mc->resizec, &one) < 0)
+ if(nbsend(mc->resizec, &one) < 0)
continue;
/* fall through */
case 'm':
@@ -122,7 +122,7 @@ initmouse(char *file, Image *i)
free(t);
mc->image = i;
mc->c = chancreate(sizeof(Mouse), 0);
- mc->resizec = chancreate(sizeof(int), 2);
+ mc->resizec = chancreate(sizeof(int), 1);
mc->pid = proccreate(_ioproc, mc, 4096);
return mc;
}