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

zhangkai.fswitch zhangkai.fswitch at gmail.com
Sun Jul 22 05:37:55 MSD 2012


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




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