[Freeswitch-dev] What is the purpose of BLOCK in switch_event.c
hi, Recently I read the codes in switch_event.c, and I am confused about the purpose of BLOCK. There are 2 locks defined in switch_event.c: static switch_mutex_t *BLOCK = NULL; static switch_thread_rwlock_t *RWLOCK = NULL; My understanding is the RWLOCK is wrlocked when binding or unbinding an event callback function, and rdlocked when executing the callback. So the RWLOCK is enough to protect multi-threads from modifying the event binding list at the same time, why we need another mutex BLOCK? And in the codes, when never the mutex BLOCK is requested to be locked, the RWLOCK must already be locked for write. like this: switch_thread_rwlock_wrlock(RWLOCK); switch_mutex_lock(BLOCK); So if BLOCK is mean to protect something, the RWLOCK is already guaranteed the exclusiveness. Please tell me if I am wrong. Regards, Kai ZHANG
You are probably right, the BLOCK is older than the write lock so its probably legacy code. but effectively its not really hurting anything. Once we release, we could try removing it and watch for regressions. On Sat, Jul 21, 2012 at 8:37 PM, zhangkai.fswitch <zhangkai.fswitch@gmail.com> wrote:
hi,
Recently I read the codes in switch_event.c, and I am confused about the purpose of BLOCK. There are 2 locks defined in switch_event.c:
static switch_mutex_t *BLOCK = NULL; static switch_thread_rwlock_t *RWLOCK = NULL;
My understanding is the RWLOCK is wrlocked when binding or unbinding an event callback function, and rdlocked when executing the callback. So the RWLOCK is enough to protect multi-threads from modifying the event binding list at the same time, why we need another mutex BLOCK?
And in the codes, when never the mutex BLOCK is requested to be locked, the RWLOCK must already be locked for write. like this:
switch_thread_rwlock_wrlock(RWLOCK); switch_mutex_lock(BLOCK);
So if BLOCK is mean to protect something, the RWLOCK is already guaranteed the exclusiveness.
Please tell me if I am wrong.
Regards,
Kai ZHANG
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
FreeSWITCH-powered IP PBX: The CudaTel Communication Server http://www.cudatel.com
Official FreeSWITCH Sites http://www.freeswitch.org http://wiki.freeswitch.org http://www.cluecon.com
Join Us At ClueCon - Aug 7-9, 2012
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
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ Twitter: http://twitter.com/FreeSWITCH_wire AIM: anthm MSN:anthony_minessale@hotmail.com GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org googletalk:conf+888@conference.freeswitch.org pstn:+19193869900
participants (2)
-
Anthony Minessale
-
zhangkai.fswitch