Ignore:
Timestamp:
Sep 19, 2006 1:37:53 PM (18 years ago)
Author:
bennylp
Message:

Fixed race-condition/deadlock problems in the dialog/user agent layer
all the way up to PJSUA-API:

  • standardized locking order: dialog then user agent, and dialog then PJSUA
  • any threads that attempt to acquire mutexes in different order than above MUST employ retry mechanism (for an example, see acquire_call() in pjsua_call.c). This retry mechanism has also been used in the UA layer (sip_ua_layer.c) since it needs to lock user agent layer first before the dialog.
  • introduced pjsip_dlg_try_inc_lock() and PJSUA_TRY_LOCK() to accomodate above.
  • pjsua tested on Quad Xeon with 4 threads and 200 cps, so far so good.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_dialog.c

    r675 r729  
    693693              dlg->sess_count)); 
    694694 
    695     pjsip_ua_lock_dlg_table(); 
    696  
    697695    pj_mutex_lock(dlg->mutex_); 
    698696    dlg->sess_count++; 
    699697 
    700     //pjsip_ua_unlock_dlg_table(); 
    701  
    702698    PJ_LOG(6,(dlg->obj_name, "Leaving pjsip_dlg_inc_lock(), sess_count=%d",  
    703699              dlg->sess_count)); 
    704700} 
    705701 
     702/* Try to acquire dialog's mutex, but bail out if mutex can not be 
     703 * acquired immediately. 
     704 */ 
     705PJ_DEF(pj_status_t) pjsip_dlg_try_inc_lock(pjsip_dialog *dlg) 
     706{ 
     707    pj_status_t status; 
     708 
     709    PJ_LOG(6,(dlg->obj_name,"Entering pjsip_dlg_try_inc_lock(), sess_count=%d",  
     710              dlg->sess_count)); 
     711 
     712    status = pj_mutex_trylock(dlg->mutex_); 
     713    if (status != PJ_SUCCESS) { 
     714        PJ_LOG(6,(dlg->obj_name, "pjsip_dlg_try_inc_lock() failed")); 
     715        return status; 
     716    } 
     717 
     718    dlg->sess_count++; 
     719 
     720    PJ_LOG(6,(dlg->obj_name, "Leaving pjsip_dlg_try_inc_lock(), sess_count=%d",  
     721              dlg->sess_count)); 
     722 
     723    return PJ_SUCCESS; 
     724} 
     725 
    706726 
    707727/* 
     
    713733    PJ_LOG(6,(dlg->obj_name, "Entering pjsip_dlg_dec_lock(), sess_count=%d",  
    714734              dlg->sess_count)); 
    715  
    716     //pjsip_ua_lock_dlg_table(); 
    717735 
    718736    pj_assert(dlg->sess_count > 0); 
     
    726744        pj_mutex_unlock(dlg->mutex_); 
    727745    } 
    728  
    729     pjsip_ua_unlock_dlg_table(); 
    730746 
    731747    PJ_LOG(6,(THIS_FILE, "Leaving pjsip_dlg_dec_lock() (dlg=%p)", dlg)); 
Note: See TracChangeset for help on using the changeset viewer.