kill.c 1.3 KB

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