Update ChangeLog.old/ChangeLog.23.
[glibc.git] / signal / allocrtsig.c
blobb79aed5f8a08678375b44417b5cd1dfa33332b03
1 /* Handle real-time signal allocation. Generic version.
2 Copyright (C) 1997-2021 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 <https://www.gnu.org/licenses/>. */
20 #include <signal.h>
21 #include <internal-signals.h>
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 #ifdef __SIGRTMIN
28 static int current_rtmin = __SIGRTMIN + RESERVED_SIGRT;
29 static int current_rtmax = __SIGRTMAX;
30 #endif
32 /* Return number of available real-time signal with highest priority. */
33 int
34 __libc_current_sigrtmin (void)
36 #ifdef __SIGRTMIN
37 return current_rtmin;
38 #else
39 return -1;
40 #endif
42 libc_hidden_def (__libc_current_sigrtmin)
44 /* Return number of available real-time signal with lowest priority. */
45 int
46 __libc_current_sigrtmax (void)
48 #ifdef __SIGRTMIN
49 return current_rtmax;
50 #else
51 return -1;
52 #endif
54 libc_hidden_def (__libc_current_sigrtmax)
56 /* Allocate real-time signal with highest/lowest available
57 priority. Please note that we don't use a lock since we assume
58 this function to be called at program start. */
59 int
60 __libc_allocate_rtsig (int high)
62 #ifndef __SIGRTMIN
63 return -1;
64 #else
65 if (current_rtmin == -1 || current_rtmin > current_rtmax)
66 /* We don't have any more signals available. */
67 return -1;
69 return high ? current_rtmin++ : current_rtmax--;
70 #endif