Changeset 708 for pjproject/trunk


Ignore:
Timestamp:
Sep 12, 2006 11:49:16 PM (18 years ago)
Author:
bennylp
Message:

Fixed mutex leaking in Linux: pj_mutex_destroy() will fail to destroy the mutex if the mutex is currently being held. Unfortunately it is quite common in the libraries to acquire the mutex first before destroying it, causing mutexes to leak. The solution is to retry unlocking/destroying the mutex several times (currently 4) while pthread_mutex_destroy() returns EBUSY

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/os_core_unix.c

    r675 r708  
    11021102PJ_DEF(pj_status_t) pj_mutex_destroy(pj_mutex_t *mutex) 
    11031103{ 
     1104    enum { RETRY = 4 }; 
    11041105    int status; 
     1106    unsigned retry; 
    11051107 
    11061108    PJ_CHECK_STACK(); 
     
    11101112    PJ_LOG(6,(mutex->obj_name, "Mutex destroyed by thread %s", 
    11111113                               pj_thread_this()->obj_name)); 
    1112     status = pthread_mutex_destroy( &mutex->mutex ); 
     1114 
     1115    for (retry=0; retry<RETRY; ++retry) { 
     1116        status = pthread_mutex_destroy( &mutex->mutex ); 
     1117        if (status == PJ_SUCCESS) 
     1118            break; 
     1119        else if (retry<RETRY-1 && status == EBUSY) 
     1120            pthread_mutex_unlock(&mutex->mutex); 
     1121    } 
     1122 
    11131123    if (status == 0) 
    11141124        return PJ_SUCCESS; 
    1115     else 
     1125    else { 
     1126        pj_assert(!"Error destroying pthread_mutex"); 
    11161127        return PJ_RETURN_OS_ERROR(status); 
     1128    } 
    11171129#else 
    11181130    pj_assert( mutex == (pj_mutex_t*)1 ); 
Note: See TracChangeset for help on using the changeset viewer.