(root)/
glibc-2.38/
signal/
allocrtsig.c
       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.
       4  
       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.
       9  
      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.
      14  
      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/>.  */
      18  
      19  #include <signal.h>
      20  #include <internal-signals.h>
      21  
      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
      30  
      31  /* Return number of available real-time signal with highest priority.  */
      32  int
      33  __libc_current_sigrtmin (void)
      34  {
      35  #ifdef __SIGRTMIN
      36    return current_rtmin;
      37  #else
      38    return -1;
      39  #endif
      40  }
      41  libc_hidden_def (__libc_current_sigrtmin)
      42  
      43  /* Return number of available real-time signal with lowest priority.  */
      44  int
      45  __libc_current_sigrtmax (void)
      46  {
      47  #ifdef __SIGRTMIN
      48    return current_rtmax;
      49  #else
      50    return -1;
      51  #endif
      52  }
      53  libc_hidden_def (__libc_current_sigrtmax)
      54  
      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)
      60  {
      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;
      67  
      68    return high ? current_rtmin++ : current_rtmax--;
      69  #endif
      70  }