2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with PulseAudio; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include <pulsecore/macro.h>
30 #include <pulsecore/flist.h>
31 #include <pulsecore/once.h>
32 #include <pulsecore/thread.h>
33 #include <pulsecore/core-util.h>
39 static void _free_rtsig(void *p) {
40 pa_rtsig_put(PA_PTR_TO_INT(p));
43 PA_STATIC_FLIST_DECLARE(rtsig_flist, pa_make_power_of_two((unsigned) (SIGRTMAX-SIGRTMIN+1)), NULL);
44 PA_STATIC_TLS_DECLARE(rtsig_tls, _free_rtsig);
46 static pa_atomic_t rtsig_current = PA_ATOMIC_INIT(-1);
48 static int rtsig_start = -1, rtsig_end = -1;
50 int pa_rtsig_get(void) {
54 if ((p = pa_flist_pop(PA_STATIC_FLIST_GET(rtsig_flist))))
55 return PA_PTR_TO_INT(p);
57 sig = pa_atomic_dec(&rtsig_current);
59 pa_assert(sig <= SIGRTMAX);
60 pa_assert(sig <= rtsig_end);
62 if (sig < rtsig_start) {
63 pa_atomic_inc(&rtsig_current);
70 int pa_rtsig_get_for_thread(void) {
74 if ((p = PA_STATIC_TLS_GET(rtsig_tls)))
75 return PA_PTR_TO_INT(p);
77 if ((sig = pa_rtsig_get()) < 0)
80 PA_STATIC_TLS_SET(rtsig_tls, PA_INT_TO_PTR(sig));
84 void pa_rtsig_put(int sig) {
85 pa_assert(sig >= rtsig_start);
86 pa_assert(sig <= rtsig_end);
88 pa_assert_se(pa_flist_push(PA_STATIC_FLIST_GET(rtsig_flist), PA_INT_TO_PTR(sig)) >= 0);
91 void pa_rtsig_configure(int start, int end) {
95 pa_assert(pa_atomic_load(&rtsig_current) == -1);
97 pa_assert(SIGRTMIN <= start);
98 pa_assert(start <= end);
99 pa_assert(end <= SIGRTMAX);
106 for (s = rtsig_start; s <= rtsig_end; s++)
107 pa_assert_se(sigaddset(&ss, s) == 0);
109 pa_assert(pthread_sigmask(SIG_BLOCK, &ss, NULL) == 0);
111 /* We allocate starting from the end */
112 pa_atomic_store(&rtsig_current, rtsig_end);
117 int pa_rtsig_get(void) {
121 int pa_rtsig_get_for_thread(void) {
125 void pa_rtsig_put(int sig) {
128 void pa_rtsig_configure(int start, int end) {
131 #endif /* SIGRTMIN */