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 /* In these variables we keep track of the used variables.  If the
00024    platform does not support any real-time signals we will define the
00025    values to some unreasonable value which will signal failing of all
00026    the functions below.  */
00027 #ifndef __SIGRTMIN
00028 static int current_rtmin = -1;
00029 static int current_rtmax = -1;
00030 #else
00031 static int current_rtmin;
00032 static int current_rtmax;
00033 
00034 static int initialized;
00035 
00036 #include <testrtsig.h>
00037 
00038 static void
00039 init (void)
00040 {
00041   if (!kernel_has_rtsig ())
00042     {
00043       current_rtmin = -1;
00044       current_rtmax = -1;
00045     }
00046   else
00047     {
00048       current_rtmin = __SIGRTMIN;
00049       current_rtmax = __SIGRTMAX;
00050     }
00051   initialized = 1;
00052 }
00053 #endif
00054 
00055 /* Return number of available real-time signal with highest priority.  */
00056 int
00057 __libc_current_sigrtmin (void)
00058 {
00059 #ifdef __SIGRTMIN
00060   if (!initialized)
00061     init ();
00062 #endif
00063   return current_rtmin;
00064 }
00065 libc_hidden_def (__libc_current_sigrtmin)
00066 
00067 /* Return number of available real-time signal with lowest priority.  */
00068 int
00069 __libc_current_sigrtmax (void)
00070 {
00071 #ifdef __SIGRTMIN
00072   if (!initialized)
00073     init ();
00074 #endif
00075   return current_rtmax;
00076 }
00077 libc_hidden_def (__libc_current_sigrtmax)
00078 
00079 /* Allocate real-time signal with highest/lowest available
00080    priority.  Please note that we don't use a lock since we assume
00081    this function to be called at program start.  */
00082 int
00083 __libc_allocate_rtsig (int high)
00084 {
00085 #ifndef __SIGRTMIN
00086   return -1;
00087 #else
00088   if (!initialized)
00089     init ();
00090   if (current_rtmin == -1 || current_rtmin > current_rtmax)
00091     /* We don't have anymore signal available.  */
00092     return -1;
00093 
00094   return high ? current_rtmin++ : current_rtmax--;
00095 #endif
00096 }