4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <pulsecore/macro.h>
32 #include <pulsecore/flist.h>
33 #include <pulsecore/once.h>
34 #include <pulsecore/thread.h>
35 #include <pulsecore/core-util.h>
41 static void _free_rtsig(void *p
) {
42 pa_rtsig_put(PA_PTR_TO_INT(p
));
45 PA_STATIC_FLIST_DECLARE(rtsig_flist
, pa_make_power_of_two(SIGRTMAX
-SIGRTMIN
+1), NULL
);
46 PA_STATIC_TLS_DECLARE(rtsig_tls
, _free_rtsig
);
48 static pa_atomic_t rtsig_current
= PA_ATOMIC_INIT(-1);
50 static int rtsig_start
= -1, rtsig_end
= -1;
52 int pa_rtsig_get(void) {
56 if ((p
= pa_flist_pop(PA_STATIC_FLIST_GET(rtsig_flist
))))
57 return PA_PTR_TO_INT(p
);
59 sig
= pa_atomic_dec(&rtsig_current
);
61 pa_assert(sig
<= SIGRTMAX
);
62 pa_assert(sig
<= rtsig_end
);
64 if (sig
< rtsig_start
) {
65 pa_atomic_inc(&rtsig_current
);
72 int pa_rtsig_get_for_thread(void) {
76 if ((p
= PA_STATIC_TLS_GET(rtsig_tls
)))
77 return PA_PTR_TO_INT(p
);
79 if ((sig
= pa_rtsig_get()) < 0)
82 PA_STATIC_TLS_SET(rtsig_tls
, PA_INT_TO_PTR(sig
));
86 void pa_rtsig_put(int sig
) {
87 pa_assert(sig
>= rtsig_start
);
88 pa_assert(sig
<= rtsig_end
);
90 pa_assert_se(pa_flist_push(PA_STATIC_FLIST_GET(rtsig_flist
), PA_INT_TO_PTR(sig
)) >= 0);
93 void pa_rtsig_configure(int start
, int end
) {
97 pa_assert(pa_atomic_load(&rtsig_current
) == -1);
99 pa_assert(SIGRTMIN
<= start
);
100 pa_assert(start
<= end
);
101 pa_assert(end
<= SIGRTMAX
);
108 for (s
= rtsig_start
; s
<= rtsig_end
; s
++)
109 pa_assert_se(sigaddset(&ss
, s
) == 0);
111 pa_assert(pthread_sigmask(SIG_BLOCK
, &ss
, NULL
) == 0);
113 /* We allocate starting from the end */
114 pa_atomic_store(&rtsig_current
, rtsig_end
);
119 int pa_rtsig_get(void) {
123 int pa_rtsig_get_for_thread(void) {
127 void pa_rtsig_put(int sig
) {
130 void pa_rtsig_configure(int start
, int end
) {
133 #endif /* SIGRTMIN */