[pulseaudio-discuss] Are "_ref" and "_unref" not necessarily called in pairs?

Colin Guthrie gmane at colin.guthr.ie
Thu May 12 02:06:25 PDT 2011


Hiya,


As per the subject question... Yes, they are supposed to be called in
pairs... BUT....

'Twas brillig, and Lin, Mengdong at 12/05/11 09:31 did gyre and gimble:
> For example, in file “module-suspend-on-idle.c “, why does the slot
> function “sink_input_state_changed_hook_cb” only reference the sink
> input but never unreference it?
> 
> So the reference count of the sink input will only increase? Does it matter?
> 
> Here is the code:   
> 
> static pa_hook_result_t sink_input_state_changed_hook_cb(pa_core *c,
> pa_sink_input *s, struct userdata *u) {
> 
>     struct device_info *d;
> 
>     pa_sink_input_state_t state;
> 
>  
> 
>     pa_assert(c);
> 
>     pa_sink_input_assert_ref(s);  … the sink input is referenced here.
> But where pa_sink_input_unref(s) is called?



This is not the same as pa_sink_input_ref(). Note the word "assert" in
the "function" call in the code above (it's actually a define, not a
function but I won't split hairs with myself :D).

Here all that is happening is ensuring that the sink_input object is
referenced...

The code is in pulsecore/object.h

See lines 91, and 69.

The code basically means assert if the object is not referenced. This is
a safefy thing to ensure good programming of modules etc.

Hope that clarifies things.

Col



-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mageia Contributor [http://www.mageia.org/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]




More information about the pulseaudio-discuss mailing list