hurd: fix build of tst-system.c
[glibc.git] / signal / allocrtsig.c
blob52640b98c5c90aaa8424f2501017fdc6b9fd07bb
1 /* Handle real-time signal allocation. Generic version.
2 Copyright (C) 1997-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <signal.h>
20 #include <internal-signals.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 #ifdef __SIGRTMIN
27 static int current_rtmin = __SIGRTMIN + RESERVED_SIGRT;
28 static int current_rtmax = __SIGRTMAX;
29 #endif
31 /* Return number of available real-time signal with highest priority. */
32 int
33 __libc_current_sigrtmin (void)
35 #ifdef __SIGRTMIN
36 return current_rtmin;
37 #else
38 return -1;
39 #endif
41 libc_hidden_def (__libc_current_sigrtmin)
43 /* Return number of available real-time signal with lowest priority. */
44 int
45 __libc_current_sigrtmax (void)
47 #ifdef __SIGRTMIN
48 return current_rtmax;
49 #else
50 return -1;
51 #endif
53 libc_hidden_def (__libc_current_sigrtmax)
55 /* Allocate real-time signal with highest/lowest available
56 priority. Please note that we don't use a lock since we assume
57 this function to be called at program start. */
58 int
59 __libc_allocate_rtsig (int high)
61 #ifndef __SIGRTMIN
62 return -1;
63 #else
64 if (current_rtmin == -1 || current_rtmin > current_rtmax)
65 /* We don't have any more signals available. */
66 return -1;
68 return high ? current_rtmin++ : current_rtmax--;
69 #endif