virtual-sink: Fix a crash when moving the sink to a new master right after setup.
[pulseaudio-raopUDP/pulseaudio-raop-alac.git] / src / pulsecore / refcnt.h
blob782436b5cd28c03ebeabe65fa9a4d65a285935b8
1 #ifndef foopulserefcnthfoo
2 #define foopulserefcnthfoo
4 /***
5 This file is part of PulseAudio.
7 Copyright 2006 Lennart Poettering
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 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
22 USA.
23 ***/
25 #include <pulsecore/atomic.h>
26 #include <pulsecore/macro.h>
27 #include <pulsecore/log.h>
29 /* #define DEBUG_REF */
31 #define PA_REFCNT_DECLARE \
32 pa_atomic_t _ref
34 #define PA_REFCNT_VALUE(p) \
35 pa_atomic_load(&(p)->_ref)
37 #define PA_REFCNT_INIT_ZERO(p) \
38 pa_atomic_store(&(p)->_ref, 0)
40 #ifndef DEBUG_REF
42 #define PA_REFCNT_INIT(p) \
43 pa_atomic_store(&(p)->_ref, 1)
45 #define PA_REFCNT_INC(p) \
46 pa_atomic_inc(&(p)->_ref)
48 #define PA_REFCNT_DEC(p) \
49 (pa_atomic_dec(&(p)->_ref)-1)
51 #else
53 /* If you need to debug ref counting problems define DEBUG_REF and
54 * set $PULSE_LOG_BACKTRACE=5 or suchlike in the shell when running
55 * PA */
57 #define PA_REFCNT_INIT(p) \
58 do { \
59 pa_atomic_store(&(p)->_ref, 1); \
60 pa_log("REF: Init %p", p); \
61 } while (FALSE)
63 #define PA_REFCNT_INC(p) \
64 do { \
65 pa_atomic_inc(&(p)->_ref); \
66 pa_log("REF: Inc %p", p); \
67 } while (FALSE) \
69 #define PA_REFCNT_DEC(p) \
70 ({ \
71 int _j = (pa_atomic_dec(&(p)->_ref)-1); \
72 if (_j <= 0) \
73 pa_log("REF: Done %p", p); \
74 else \
75 pa_log("REF: Dec %p", p); \
76 _j; \
79 #endif
81 #endif