Blob


1 #include <u.h>
2 #include <signal.h>
3 #include "threadimpl.h"
5 static void tinterrupt(Proc*, Thread*);
7 static void
8 threadxxxgrp(int grp, int dokill)
9 {
10 Proc *p;
11 Thread *t;
13 lock(&_threadpq.lock);
14 for(p=_threadpq.head; p; p=p->next){
15 lock(&p->lock);
16 for(t=p->threads.head; t; t=t->nextt)
17 if(t->grp == grp){
18 if(dokill)
19 t->moribund = 1;
20 tinterrupt(p, t);
21 }
22 unlock(&p->lock);
23 }
24 unlock(&_threadpq.lock);
25 _threadbreakrendez();
26 }
28 static void
29 threadxxx(int id, int dokill)
30 {
31 Proc *p;
32 Thread *t;
34 lock(&_threadpq.lock);
35 for(p=_threadpq.head; p; p=p->next){
36 lock(&p->lock);
37 for(t=p->threads.head; t; t=t->nextt)
38 if(t->id == id){
39 if(dokill)
40 t->moribund = 1;
41 tinterrupt(p, t);
42 unlock(&p->lock);
43 unlock(&_threadpq.lock);
44 _threadbreakrendez();
45 return;
46 }
47 unlock(&p->lock);
48 }
49 unlock(&_threadpq.lock);
50 _threaddebug(DBGNOTE, "Can't find thread to kill");
51 return;
52 }
54 void
55 threadkillgrp(int grp)
56 {
57 threadxxxgrp(grp, 1);
58 }
60 void
61 threadkill(int id)
62 {
63 threadxxx(id, 1);
64 }
66 void
67 threadintgrp(int grp)
68 {
69 threadxxxgrp(grp, 0);
70 }
72 void
73 threadint(int id)
74 {
75 threadxxx(id, 0);
76 }
78 static void
79 tinterrupt(Proc *p, Thread *t)
80 {
81 switch(t->state){
82 case Running:
83 kill(p->pid, SIGINT);
84 // postnote(PNPROC, p->pid, "threadint");
85 break;
86 case Rendezvous:
87 _threadflagrendez(t);
88 break;
89 }
90 }