allocrtsig.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Handle real-time signal allocation.
  2. Copyright (C) 1997,98,99,2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <signal.h>
  18. /* Sanity check. */
  19. #if !defined __SIGRTMIN || (__SIGRTMAX - __SIGRTMIN) < 3
  20. # error "This must not happen"
  21. #endif
  22. static int current_rtmin;
  23. static int current_rtmax;
  24. static int initialized;
  25. #include <testrtsig.h>
  26. static void
  27. init (void)
  28. {
  29. if (!kernel_has_rtsig ())
  30. {
  31. current_rtmin = -1;
  32. current_rtmax = -1;
  33. }
  34. else
  35. {
  36. current_rtmin = __SIGRTMIN + 3;
  37. current_rtmax = __SIGRTMAX;
  38. }
  39. initialized = 1;
  40. }
  41. /* Return number of available real-time signal with highest priority. */
  42. int
  43. __libc_current_sigrtmin (void)
  44. {
  45. if (!initialized)
  46. init ();
  47. return current_rtmin;
  48. }
  49. strong_alias (__libc_current_sigrtmin, __libc_current_sigrtmin_private)
  50. libc_hidden_def (__libc_current_sigrtmin)
  51. /* Return number of available real-time signal with lowest priority. */
  52. int
  53. __libc_current_sigrtmax (void)
  54. {
  55. if (!initialized)
  56. init ();
  57. return current_rtmax;
  58. }
  59. strong_alias (__libc_current_sigrtmax, __libc_current_sigrtmax_private)
  60. libc_hidden_def (__libc_current_sigrtmax)
  61. /* Allocate real-time signal with highest/lowest available
  62. priority. Please note that we don't use a lock since we assume
  63. this function to be called at program start. */
  64. int
  65. __libc_allocate_rtsig (int high)
  66. {
  67. if (!initialized)
  68. init ();
  69. if (current_rtmin == -1 || current_rtmin > current_rtmax)
  70. /* We don't have anymore signal available. */
  71. return -1;
  72. return high ? current_rtmin++ : current_rtmax--;
  73. }
  74. strong_alias (__libc_allocate_rtsig, __libc_allocate_rtsig_private)