[Freeswitch-dev] Safely Traversing call lists
Ronnie Beck
ronybeck at themenz.biz
Tue Sep 15 15:44:00 MSD 2015
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
Join us at ClueCon 2014 Aug 4-7, 2014
More information about the FreeSWITCH-dev
mailing list