[asterisk-dev] Is this locking sequence correct?

Kirill Katsnelson kkm at adaptiveai.com
Thu Feb 3 02:53:41 CST 2011


I am probably missing something about locking. Here is a trimmed down 
piece of code from chan_sip.c:

if (p->owner) {
   struct ast_channel *owner = p->owner;
   ast_channel_ref(owner);
   sip_pvt_unlock(p);
   ast_channel_unlock(owner);
     /* ... Do something interesting here ...  */
   ast_channel_unref(owner);
     /* Oops, or not? */
   sip_pvt_lock(p);
}

My question is about the 2 last calls. After ast_channel_unref(), the 
channel is neither locked nor referenced. Can the channel then just go 
away such that sip_pvt_lock() might be too late to call already? Is it 
more correct to call sip_pvt_lock() before ast_channel_unref(), or am I 
just misunderstanding the semantics? Is it guaranteed here that 
ast_channel_unref() does not unref the last reference?

  -kkm



More information about the asterisk-dev mailing list