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 
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10 
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15 
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19 
20 #include <features.h>
21 #include <signal.h>
22 #include <sys/syscall.h>
23 
24 /* Only enable rt signals when it is supported at compile time */
25 #ifndef __NR_rt_sigaction
26 /* In these variables we keep track of the used variables.  If the
27    platform does not support any real-time signals we will define the
28    values to some unreasonable value which will signal failing of all
29    the functions below.  */
30 static int current_rtmin = -1;
31 static int current_rtmax = -1;
32 #else
33 # ifdef __UCLIBC_HAS_THREADS_NATIVE__
34 static int current_rtmin = __SIGRTMIN + 2;
35 # elif defined __UCLIBC_HAS_THREADS__ && !defined __UCLIBC_HAS_LINUXTHREADS__
36 /* psm: might be good for LT old as well, do not want to break it for now */
37 /* Sanity check */
38 #  if !defined __SIGRTMIN || (__SIGRTMAX - __SIGRTMIN) < 3
39 #   error "This must not happen"
40 #  endif
41 static int current_rtmin = __SIGRTMIN + 3;
42 # else
43 static int current_rtmin = __SIGRTMIN;
44 # endif
45 static int current_rtmax = __SIGRTMAX;
46 #endif
47 
48 /* Return number of available real-time signal with highest priority.  */
__libc_current_sigrtmin(void)49 int __libc_current_sigrtmin (void)
50 {
51   return current_rtmin;
52 }
53 
54 /* Return number of available real-time signal with lowest priority.  */
__libc_current_sigrtmax(void)55 int __libc_current_sigrtmax (void)
56 {
57   return current_rtmax;
58 }
59 
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 __libc_allocate_rtsig (int high);
65 int __libc_allocate_rtsig (int high)
66 {
67   if (current_rtmin == -1 || current_rtmin > current_rtmax)
68     /* We don't have anymore signal available.  */
69     return -1;
70 
71   return high ? current_rtmin++ : current_rtmax--;
72 }
73 #endif
74