[Freeswitch-dev] What is the purpose of BLOCK in switch_event.c

Anthony Minessale anthony.minessale at gmail.com
Mon Jul 23 21:28:12 MSD 2012


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 at 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 at freeswitch.org
> http://www.freeswitchsolutions.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 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



-- 
Anthony Minessale II

FreeSWITCH http://www.freeswitch.org/
ClueCon http://www.cluecon.com/
Twitter: http://twitter.com/FreeSWITCH_wire

AIM: anthm
MSN:anthony_minessale at hotmail.com
GTALK/JABBER/PAYPAL:anthony.minessale at gmail.com
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888 at conference.freeswitch.org
googletalk:conf+888 at conference.freeswitch.org
pstn:+19193869900



Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-dev mailing list