preempt-sig.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 1994-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <hurd/sigpreempt.h>
  15. #include <hurd/signal.h>
  16. #include <assert.h>
  17. void
  18. hurd_preempt_signals (struct hurd_signal_preemptor *preemptor)
  19. {
  20. __mutex_lock (&_hurd_siglock);
  21. preemptor->next = _hurdsig_preemptors;
  22. _hurdsig_preemptors = preemptor;
  23. _hurdsig_preempted_set |= preemptor->signals;
  24. __mutex_unlock (&_hurd_siglock);
  25. }
  26. void
  27. hurd_unpreempt_signals (struct hurd_signal_preemptor *preemptor)
  28. {
  29. struct hurd_signal_preemptor **p;
  30. sigset_t preempted = 0;
  31. __mutex_lock (&_hurd_siglock);
  32. p = &_hurdsig_preemptors;
  33. while (*p)
  34. if (*p == preemptor)
  35. {
  36. /* Found it; take it off the chain. */
  37. *p = (*p)->next;
  38. if ((preemptor->signals & preempted) != preemptor->signals)
  39. {
  40. /* This might have been the only preemptor for some
  41. of those signals, so we must collect the full mask
  42. from the others. */
  43. struct hurd_signal_preemptor *pp;
  44. for (pp = *p; pp; pp = pp->next)
  45. preempted |= pp->signals;
  46. _hurdsig_preempted_set = preempted;
  47. }
  48. __mutex_unlock (&_hurd_siglock);
  49. return;
  50. }
  51. else
  52. {
  53. preempted |= (*p)->signals;
  54. p = &(*p)->next;
  55. }
  56. __mutex_unlock (&_hurd_siglock); /* Avoid deadlock during death rattle. */
  57. assert (! "removing absent preemptor");
  58. }