ChangeLog fix
[glibc.git] / signal / allocrtsig.c
blobb3b77cfb1efae03ef779fcc60fe0f8639eec8503
1 /* Handle real-time signal allocation.
2 Copyright (C) 1997-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
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.
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.
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/>. */
20 #include <signal.h>
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 #ifndef __SIGRTMIN
27 static int current_rtmin = -1;
28 static int current_rtmax = -1;
29 #else
30 static int current_rtmin;
31 static int current_rtmax;
33 static int initialized;
35 #include <testrtsig.h>
37 static void
38 init (void)
40 if (!kernel_has_rtsig ())
42 current_rtmin = -1;
43 current_rtmax = -1;
45 else
47 current_rtmin = __SIGRTMIN;
48 current_rtmax = __SIGRTMAX;
50 initialized = 1;
52 #endif
54 /* Return number of available real-time signal with highest priority. */
55 int
56 __libc_current_sigrtmin (void)
58 #ifdef __SIGRTMIN
59 if (!initialized)
60 init ();
61 #endif
62 return current_rtmin;
64 libc_hidden_def (__libc_current_sigrtmin)
66 /* Return number of available real-time signal with lowest priority. */
67 int
68 __libc_current_sigrtmax (void)
70 #ifdef __SIGRTMIN
71 if (!initialized)
72 init ();
73 #endif
74 return current_rtmax;
76 libc_hidden_def (__libc_current_sigrtmax)
78 /* Allocate real-time signal with highest/lowest available
79 priority. Please note that we don't use a lock since we assume
80 this function to be called at program start. */
81 int
82 __libc_allocate_rtsig (int high)
84 #ifndef __SIGRTMIN
85 return -1;
86 #else
87 if (!initialized)
88 init ();
89 if (current_rtmin == -1 || current_rtmin > current_rtmax)
90 /* We don't have anymore signal available. */
91 return -1;
93 return high ? current_rtmin++ : current_rtmax--;
94 #endif