Changeset 3928


Ignore:
Timestamp:
Dec 28, 2011 9:49:24 AM (12 years ago)
Author:
nanang
Message:

Close #1434: Added PJSUA_LOCK_IS_LOCKED().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r3901 r3928  
    367367    pj_pool_t           *pool;      /**< pjsua's private pool.          */ 
    368368    pj_mutex_t          *mutex;     /**< Mutex protection for this data */ 
     369    unsigned             mutex_nesting_level; /**< Mutex nesting level. */ 
     370    pj_thread_t         *mutex_owner; /**< Mutex owner.                 */ 
    369371    pjsua_state          state;     /**< Library state.                 */ 
    370372 
     
    503505 
    504506#if 1 
    505 #define PJSUA_LOCK()        pj_mutex_lock(pjsua_var.mutex) 
    506 #define PJSUA_TRY_LOCK()    pj_mutex_trylock(pjsua_var.mutex) 
    507 #define PJSUA_UNLOCK()      pj_mutex_unlock(pjsua_var.mutex) 
     507 
     508PJ_INLINE(void) PJSUA_LOCK() 
     509{ 
     510    pj_mutex_lock(pjsua_var.mutex); 
     511    pjsua_var.mutex_owner = pj_thread_this(); 
     512    ++pjsua_var.mutex_nesting_level; 
     513} 
     514 
     515PJ_INLINE(void) PJSUA_UNLOCK() 
     516{ 
     517    if (--pjsua_var.mutex_nesting_level == 0) 
     518        pjsua_var.mutex_owner = NULL; 
     519    pj_mutex_unlock(pjsua_var.mutex); 
     520} 
     521 
     522PJ_INLINE(pj_status_t) PJSUA_TRY_LOCK() 
     523{ 
     524    pj_status_t status; 
     525    status = pj_mutex_trylock(pjsua_var.mutex); 
     526    if (status == PJ_SUCCESS) { 
     527        pjsua_var.mutex_owner = pj_thread_this(); 
     528        ++pjsua_var.mutex_nesting_level; 
     529    } 
     530    return status; 
     531} 
     532 
     533PJ_INLINE(pj_bool_t) PJSUA_LOCK_IS_LOCKED() 
     534{ 
     535    return pjsua_var.mutex_owner == pj_thread_this(); 
     536} 
     537 
    508538#else 
    509539#define PJSUA_LOCK() 
    510 #define PJSUA_TRY_LOCK()    PJ_SUCCESS 
     540#define PJSUA_TRY_LOCK()        PJ_SUCCESS 
    511541#define PJSUA_UNLOCK() 
     542#define PJSUA_LOCK_IS_LOCKED()  PJ_TRUE 
    512543#endif 
    513544 
Note: See TracChangeset for help on using the changeset viewer.