[Freeswitch-dev] Execution of channel functions and thread safety
Peter Olsson
peter.olsson at visionutveckling.se
Sat Jul 23 17:58:37 MSD 2011
Hello all developers!
I'm in the middle of the development of my own FreeSWITCH module, written in C. Since I've been following the project for quite some time now, it was pretty easy to get things going :) And most of the Core API is straight forward to use - thanks for that all FS developers!
I have a minor question of some of the channel functions in FreeSWITCH, and if it's safe to call them from different threads (outside the channel's own thread).
For instance; I have a dialplan app registered, and when the call arrives there I do some minor parsing of the call, and after that I park the call (using switch_ivr_park()).
Now to my question, I understand that it's probably not safe to call switch_ivr_play_file() from another thread at this time, since the park app itself will then try to handle RTP at the same time as switch_ivr_play_file() (especially if park app sends silence frames) - so instead I queue this to the "playback" app on the channel, similar to how it's done in mod_event_socket. But, what if I call switch_channel_answer(), switch_channel_pre_answer() etc, is that safe to call from another thread, or should I queue these messages to the channel instead - so they are executed within the channel's own thread?
My first thought was that these were supposed to be executed by the channel's thread only, but after looking at some of the uuid_-commands in mod_commands I'm not so sure anymore. Since there are quite a few commands messing with the channel's states etc, and that would be executed from another thread indeed (for instance hold/unhold, kill etc).
Right now I'm calling switch_channel_answer() from another thread, and it works great, however, I want to be sure I do it right, so this won't cause any problems for me later on in the project.
Regards,
Peter Olsson
PS! See you at ClueCon!
More information about the FreeSWITCH-dev
mailing list