allocrtsig.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Handle real-time signal allocation.
  2. Copyright (C) 1997, 1998, 1999 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 Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. 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. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. Boston, MA 02111-1307, USA. */
  17. #include <signal.h>
  18. #include <sys/types.h>
  19. #include <sys/syscall.h>
  20. /* Only enable rt signals when it is supported at compile time */
  21. #ifdef __NR_rt_sigaction
  22. /* In these variables we keep track of the used variables. If the
  23. platform does not support any real-time signals we will define the
  24. values to some unreasonable value which will signal failing of all
  25. the functions below. */
  26. static int current_rtmin = __SIGRTMIN;
  27. static int current_rtmax = __SIGRTMAX;
  28. #ifdef _POSIX_THREADS
  29. /* Allocate real-time signal with highest/lowest available
  30. priority. Please note that we don't use a lock since we assume
  31. this function to be called at program start. */
  32. int __libc_allocate_rtsig (int high)
  33. {
  34. if (current_rtmin > current_rtmax)
  35. /* We don't have anymore signals available. */
  36. return -1;
  37. return high ? current_rtmin++ : current_rtmax--;
  38. }
  39. #endif
  40. /* Return number of available real-time signal with highest priority. */
  41. int __libc_current_sigrtmin (void)
  42. {
  43. return current_rtmin;
  44. }
  45. /* Return number of available real-time signal with lowest priority. */
  46. int __libc_current_sigrtmax (void)
  47. {
  48. return current_rtmax;
  49. }
  50. #else
  51. #ifdef _POSIX_THREADS
  52. int __libc_allocate_rtsig (int high)
  53. {
  54. return -1;
  55. }
  56. #endif
  57. int __libc_current_sigrtmin (void)
  58. {
  59. return -1;
  60. }
  61. int __libc_current_sigrtmax (void)
  62. {
  63. return -1;
  64. }
  65. #endif