kill.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <thread.h>
  12. #include "threadimpl.h"
  13. static void tinterrupt(Proc*, Thread*);
  14. static void
  15. threadxxxgrp(int grp, int dokill)
  16. {
  17. Proc *p;
  18. Thread *t;
  19. lock(&_threadpq.lock);
  20. for(p=_threadpq.head; p; p=p->next){
  21. lock(&p->lock);
  22. for(t=p->threads.head; t; t=t->nextt)
  23. if(t->grp == grp){
  24. if(dokill)
  25. t->moribund = 1;
  26. tinterrupt(p, t);
  27. }
  28. unlock(&p->lock);
  29. }
  30. unlock(&_threadpq.lock);
  31. _threadbreakrendez();
  32. }
  33. static void
  34. threadxxx(int id, int dokill)
  35. {
  36. Proc *p;
  37. Thread *t;
  38. lock(&_threadpq.lock);
  39. for(p=_threadpq.head; p; p=p->next){
  40. lock(&p->lock);
  41. for(t=p->threads.head; t; t=t->nextt)
  42. if(t->id == id){
  43. if(dokill)
  44. t->moribund = 1;
  45. tinterrupt(p, t);
  46. unlock(&p->lock);
  47. unlock(&_threadpq.lock);
  48. _threadbreakrendez();
  49. return;
  50. }
  51. unlock(&p->lock);
  52. }
  53. unlock(&_threadpq.lock);
  54. _threaddebug(DBGNOTE, "Can't find thread to kill");
  55. return;
  56. }
  57. void
  58. threadkillgrp(int grp)
  59. {
  60. threadxxxgrp(grp, 1);
  61. }
  62. void
  63. threadkill(int id)
  64. {
  65. threadxxx(id, 1);
  66. }
  67. void
  68. threadintgrp(int grp)
  69. {
  70. threadxxxgrp(grp, 0);
  71. }
  72. void
  73. threadint(int id)
  74. {
  75. threadxxx(id, 0);
  76. }
  77. static void
  78. tinterrupt(Proc *p, Thread *t)
  79. {
  80. switch(t->state){
  81. case Running:
  82. postnote(PNPROC, p->pid, "threadint");
  83. break;
  84. case Rendezvous:
  85. _threadflagrendez(t);
  86. break;
  87. case Dead:
  88. case Ready:
  89. break;
  90. }
  91. }