]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/generic/allocrtsig.c
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / generic / allocrtsig.c
CommitLineData
b7cb624b
UD
1/* Handle real-time signal allocation.
2 Copyright (C) 1997,98,99,2002 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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21#include <signal.h>
22
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#ifndef __SIGRTMIN
28static int current_rtmin = -1;
29static int current_rtmax = -1;
30#else
31static int current_rtmin;
32static int current_rtmax;
33
34static int initialized;
35
b323b11c 36#include <testrtsig.h>
b7cb624b
UD
37
38static void
39init (void)
40{
41 if (!kernel_has_rtsig ())
42 {
43 current_rtmin = -1;
44 current_rtmax = -1;
45 }
46 else
47 {
48 current_rtmin = __SIGRTMIN;
49 current_rtmax = __SIGRTMAX;
50 }
51 initialized = 1;
52}
53#endif
54
55/* Return number of available real-time signal with highest priority. */
56int
57__libc_current_sigrtmin (void)
58{
59#ifdef __SIGRTMIN
60 if (!initialized)
61 init ();
62#endif
63 return current_rtmin;
64}
a4baf360 65libc_hidden_def (__libc_current_sigrtmin)
b7cb624b
UD
66
67/* Return number of available real-time signal with lowest priority. */
68int
69__libc_current_sigrtmax (void)
70{
71#ifdef __SIGRTMIN
72 if (!initialized)
73 init ();
74#endif
75 return current_rtmax;
76}
a4baf360 77libc_hidden_def (__libc_current_sigrtmax)
b7cb624b
UD
78
79/* Allocate real-time signal with highest/lowest available
80 priority. Please note that we don't use a lock since we assume
81 this function to be called at program start. */
82int
83__libc_allocate_rtsig (int high)
84{
85#ifndef __SIGRTMIN
86 return -1;
87#else
88 if (!initialized)
89 init ();
90 if (current_rtmin == -1 || current_rtmin > current_rtmax)
91 /* We don't have anymore signal available. */
92 return -1;
93
94 return high ? current_rtmin++ : current_rtmax--;
95#endif
96}