Back to index

glibc  2.9
allocrtsig.c
Go to the documentation of this file.
00001 /* Handle real-time signal allocation.
00002    Copyright (C) 1997,98,99,2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <signal.h>
00022 
00023 /* Sanity check.  */
00024 #if !defined __SIGRTMIN || (__SIGRTMAX - __SIGRTMIN) < 3
00025 # error "This must not happen"
00026 #endif
00027 
00028 static int current_rtmin;
00029 static int current_rtmax;
00030 
00031 static int initialized;
00032 
00033 #include <testrtsig.h>
00034 
00035 static void
00036 init (void)
00037 {
00038   if (!kernel_has_rtsig ())
00039     {
00040       current_rtmin = -1;
00041       current_rtmax = -1;
00042     }
00043   else
00044     {
00045       current_rtmin = __SIGRTMIN + 3;
00046       current_rtmax = __SIGRTMAX;
00047     }
00048   initialized = 1;
00049 }
00050 
00051 /* Return number of available real-time signal with highest priority.  */
00052 int
00053 __libc_current_sigrtmin (void)
00054 {
00055   if (!initialized)
00056     init ();
00057   return current_rtmin;
00058 }
00059 strong_alias (__libc_current_sigrtmin, __libc_current_sigrtmin_private);
00060 libc_hidden_def (__libc_current_sigrtmin)
00061 
00062 /* Return number of available real-time signal with lowest priority.  */
00063 int
00064 __libc_current_sigrtmax (void)
00065 {
00066   if (!initialized)
00067     init ();
00068   return current_rtmax;
00069 }
00070 strong_alias (__libc_current_sigrtmax, __libc_current_sigrtmax_private);
00071 libc_hidden_def (__libc_current_sigrtmax)
00072 
00073 /* Allocate real-time signal with highest/lowest available
00074    priority.  Please note that we don't use a lock since we assume
00075    this function to be called at program start.  */
00076 int
00077 __libc_allocate_rtsig (int high)
00078 {
00079   if (!initialized)
00080     init ();
00081   if (current_rtmin == -1 || current_rtmin > current_rtmax)
00082     /* We don't have anymore signal available.  */
00083     return -1;
00084 
00085   return high ? current_rtmin++ : current_rtmax--;
00086 }
00087 strong_alias (__libc_allocate_rtsig, __libc_allocate_rtsig_private);