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@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@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@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-dev http://www.freeswitch.org