Blob


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