[Freeswitch-dev] Safely Traversing call lists
Michael Jerris
mike at jerris.com
Mon Oct 12 21:41:33 MSD 2015
check out similar function that could show you how to do the locking and iterating safely
switch_core_session_hupall_matching_var_ans
> On Sep 15, 2015, at 7:43 AM, Ronnie Beck <ronybeck at themenz.biz> wrote:
>
> Hi All,
>
> I have just a small question about the thread safety of the following code:
>
> switch_console_callback_match_t *callList = switch_core_session_findall();
> for( node = callList->head; node; node = node->next )
> {
> switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s)
> Checking session '%s'\n", __FUNCTION__, node->val);
> }
>
> I just want to check some specific channel variables on all the active
> calls on a Freeswitch server. However it seems to me that while
> traversing the list, it is possible that "node" could be deleted by
> freeswitch while my code is still using it. Is there some sort of
> protection I should be doing in order to safely traverse the list and
> investigate each session?
>
> I thought I could lock each session as I interrogate the session however
> this doesn't protect against the situation where the "next" node is
> deleted as my code switches to that node. In C++, if you traverse a
> list with an iterator, changes to the list invalidate the iterator. So
> one must obtain a new iterator each time the list is changed. But I
> don't see how to do this with the list provided by
> switch_core_session_findall().
>
> Any tips?
>
> Cheers,
>
> Ronnie Beck
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-dev mailing list
> FreeSWITCH-dev at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev
> http://www.freeswitch.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-dev/attachments/20151012/e548e131/attachment.html
Join us at ClueCon 2014 Aug 4-7, 2014
More information about the FreeSWITCH-dev
mailing list