git: 9front

Download patch

ref: 6570f6eb2126976ce1472aa8d1930f899ebf4fd4
parent: 9e913b56e07839e4f3662ab429c3c8dba2bb44ef
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Aug 9 23:48:37 EDT 2015

libthread: use "interrupt" proc ctl message instead of posting a note for threadint()

threadint() is called to interrupt channel operation or a system call.
the kernel provides a new "interrupt" procctl message to interrupt a
process commited to or being in a blocking syscall, which is similar,
but not the same. the main difference is that "interrupt" condition
is not cleared before the process actually attempts to block. also
can be cleared with "nointerrupt" ctl message. see proc(3)

--- a/sys/src/libthread/kill.c
+++ b/sys/src/libthread/kill.c
@@ -79,8 +79,20 @@
 static void
 tinterrupt(Proc *p, Thread *t)
 {
+	char buf[64];
+	int fd;
+
 	switch(t->state){
 	case Running:
+		snprint(buf, sizeof(buf), "/proc/%d/ctl", p->pid);
+		fd = open(buf, OWRITE|OCEXEC);
+		if(fd >= 0){
+			if(write(fd, "interrupt", 9) == 9){
+				close(fd);
+				break;
+			}
+			close(fd);
+		}
 		postnote(PNPROC, p->pid, "threadint");
 		break;
 	case Rendezvous:
--