lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* Handle real-time signal allocation. |
| 2 | Copyright (C) 1997, 1998, 1999 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 <features.h> |
| 22 | #include <signal.h> |
| 23 | #include <sys/types.h> |
| 24 | #include <sys/syscall.h> |
| 25 | |
| 26 | /* Only enable rt signals when it is supported at compile time */ |
| 27 | #ifndef __NR_rt_sigaction |
| 28 | /* In these variables we keep track of the used variables. If the |
| 29 | platform does not support any real-time signals we will define the |
| 30 | values to some unreasonable value which will signal failing of all |
| 31 | the functions below. */ |
| 32 | static int current_rtmin = -1; |
| 33 | static int current_rtmax = -1; |
| 34 | #else |
| 35 | # ifdef __UCLIBC_HAS_THREADS_NATIVE__ |
| 36 | static int current_rtmin = __SIGRTMIN + 2; |
| 37 | # else |
| 38 | static int current_rtmin = __SIGRTMIN; |
| 39 | # endif |
| 40 | static int current_rtmax = __SIGRTMAX; |
| 41 | #endif |
| 42 | |
| 43 | /* Return number of available real-time signal with highest priority. */ |
| 44 | int __libc_current_sigrtmin (void) |
| 45 | { |
| 46 | return current_rtmin; |
| 47 | } |
| 48 | |
| 49 | /* Return number of available real-time signal with lowest priority. */ |
| 50 | int __libc_current_sigrtmax (void) |
| 51 | { |
| 52 | return current_rtmax; |
| 53 | } |
| 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 __libc_allocate_rtsig (int high); |
| 59 | int __libc_allocate_rtsig (int high) |
| 60 | { |
| 61 | if (current_rtmin == -1 || current_rtmin > current_rtmax) |
| 62 | /* We don't have anymore signal available. */ |
| 63 | return -1; |
| 64 | |
| 65 | return high ? current_rtmin++ : current_rtmax--; |
| 66 | } |