shithub: riscv

Download patch

ref: c23504631008ce0bfaa5bec48acb2b04f4b49fd9
parent: a98f911a178d3cc044d612e5ad96ee487bd887c8
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: