Update.
[platform/upstream/glibc.git] / signal / allocrtsig.c
1 /* Handle real-time signal allocation.
2    Copyright (C) 1997 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 Library General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    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    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public
17    License along with the GNU C Library; see the file COPYING.LIB.  If not,
18    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 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
28 static int current_rtmin = -1;
29 static int current_rtmax = -1;
30 #else
31 static int current_rtmin = __SIGRTMIN;
32 static int current_rtmax = __SIGRTMAX;
33
34 static int initialized;
35
36 #include "testrtsig.h"
37
38 static void
39 init (void)
40 {
41   if (!kernel_has_rtsig ())
42     {
43       current_rtmin = -1;
44       current_rtmax = -1;
45     }
46   initialized = 1;
47 }
48 #endif
49
50 /* Return number of available real-time signal with highest priority.  */
51 int
52 __libc_current_sigrtmin (void)
53 {
54 #ifdef __SIGRTMIN
55   if (!initialized)
56     init ();
57 #endif
58   return current_rtmin;
59 }
60
61 /* Return number of available real-time signal with lowest priority.  */
62 int
63 __libc_current_sigrtmax (void)
64 {
65 #ifdef __SIGRTMIN
66   if (!initialized)
67     init ();
68 #endif
69   return current_rtmax;
70 }
71
72 /* Allocate real-time signal with highest/lowest available
73    priority.  Please note that we don't use a lock since we assume
74    this function to be called at program start.  */
75 int
76 __libc_allocate_rtsig (int high)
77 {
78 #ifndef __SIGRTMIN
79   return -1;
80 #else
81   if (!initialized)
82     init ();
83   if (current_rtmin != -1 || current_rtmin > current_rtmax)
84     /* We don't have anymore signal available.  */
85     return -1;
86
87   return high ? current_rtmin++ : current_rtmax--;
88 #endif
89 }