allocrtsig.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <signal.h>
  17. /* Sanity check. */
  18. #if !defined __SIGRTMIN || (__SIGRTMAX - __SIGRTMIN) < 3
  19. # error "This must not happen"
  20. #endif
  21. static int current_rtmin;
  22. static int current_rtmax;
  23. static int initialized;
  24. #include <testrtsig.h>
  25. static void
  26. init (void)
  27. {
  28. if (!kernel_has_rtsig ())
  29. {
  30. current_rtmin = -1;
  31. current_rtmax = -1;
  32. }
  33. else
  34. {
  35. current_rtmin = __SIGRTMIN + 3;
  36. current_rtmax = __SIGRTMAX;
  37. }
  38. initialized = 1;
  39. }
  40. /* Return number of available real-time signal with highest priority. */
  41. int
  42. __libc_current_sigrtmin (void)
  43. {
  44. if (!initialized)
  45. init ();
  46. return current_rtmin;
  47. }
  48. strong_alias (__libc_current_sigrtmin, __libc_current_sigrtmin_private)
  49. libc_hidden_def (__libc_current_sigrtmin)
  50. /* Return number of available real-time signal with lowest priority. */
  51. int
  52. __libc_current_sigrtmax (void)
  53. {
  54. if (!initialized)
  55. init ();
  56. return current_rtmax;
  57. }
  58. strong_alias (__libc_current_sigrtmax, __libc_current_sigrtmax_private)
  59. libc_hidden_def (__libc_current_sigrtmax)
  60. #if 0
  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)
  75. #endif