[libnice] multithread g_main_loop_quit ad remove agent

Philip Withnall philip at tecnocode.co.uk
Tue Jul 15 06:16:40 PDT 2014


On Mon, 2014-07-14 at 18:01 +0200, Emanuele Bizzarri wrote:
> 
> On 14/07/2014 14:27, Philip Withnall wrote:
> 
> > You can still implement your own reference counting for the user_data.
> > If it is a struct, just add a new member:
> >     volatile int ref_count;
> > and thread-safe ref and unref functions:
> >     MyStruct *my_struct_ref (MyStruct *self) {
> >         g_atomic_int_inc (&self->ref_count);
> >         return self;
> >     }
> > and:
> >     void my_struct_unref (MyStruct *self) {
> >         if (g_atomic_int_dec_and_test (&self->ref_count)) {
> >             /* Free the structure here. */
> >         }
> >     }
> To implement this I need two points inside the the code runned by the
> main loop thread in which change the reference count and check for
> destruction.
> Can I use change state NICE_COMPONENT_STATE_GATHERING to increase
> ref_count
> and 
> streams-removed to decrease it?

It really depends on when you're going to access the data structure from
your code. The general rule is to increment the reference count for each
pointer you hold to the data structure. I would guess you should
reference it when you pass it into nice_agent_attach_recv(), and
dereference it in the callback for streams-removed, as you say. That
will keep the structure alive for the lifespan of the stream.

Philip
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 213 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/nice/attachments/20140715/eaa05e99/attachment.sig>


More information about the nice mailing list