allocrtsig.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <features.h>
  18. #include <signal.h>
  19. #include <sys/types.h>
  20. #include <sys/syscall.h>
  21. /* Only enable rt signals when it is supported at compile time */
  22. #ifdef __NR_rt_sigaction
  23. /* In these variables we keep track of the used variables. If the
  24. platform does not support any real-time signals we will define the
  25. values to some unreasonable value which will signal failing of all
  26. the functions below. */
  27. static int current_rtmin = __SIGRTMIN;
  28. static int current_rtmax = __SIGRTMAX;
  29. #ifdef __UCLIBC_HAS_THREADS__
  30. /* Allocate real-time signal with highest/lowest available
  31. priority. Please note that we don't use a lock since we assume
  32. this function to be called at program start. */
  33. int __libc_allocate_rtsig (int high)
  34. {
  35. if (current_rtmin > current_rtmax)
  36. /* We don't have anymore signals available. */
  37. return -1;
  38. return high ? current_rtmin++ : current_rtmax--;
  39. }
  40. #endif
  41. /* Return number of available real-time signal with highest priority. */
  42. int __libc_current_sigrtmin (void)
  43. {
  44. return current_rtmin;
  45. }
  46. /* Return number of available real-time signal with lowest priority. */
  47. int __libc_current_sigrtmax (void)
  48. {
  49. return current_rtmax;
  50. }
  51. #else
  52. #ifdef __UCLIBC_HAS_THREADS__
  53. int __libc_allocate_rtsig (int high)
  54. {
  55. return -1;
  56. }
  57. #endif
  58. int __libc_current_sigrtmin (void)
  59. {
  60. return -1;
  61. }
  62. int __libc_current_sigrtmax (void)
  63. {
  64. return -1;
  65. }
  66. #endif