Ignore:
Timestamp:
Jul 22, 2009 11:12:35 AM (15 years ago)
Author:
bennylp
Message:

Ticket #922: Option to enable mutex related logging to assist troubleshooting concurrency problems

File:
1 edited

Legend:

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

    r2394 r2843  
    3939#endif 
    4040 
     41/* Activate mutex related logging if PJ_DEBUG_MUTEX is set, otherwise 
     42 * use default level 6 logging. 
     43 */ 
     44#if defined(PJ_DEBUG_MUTEX) && PJ_DEBUG_MUTEX 
     45#   undef PJ_DEBUG 
     46#   define PJ_DEBUG         1 
     47#   define LOG_MUTEX(expr)  PJ_LOG(5,expr) 
     48#else 
     49#   define LOG_MUTEX(expr)  PJ_LOG(6,expr) 
     50#endif 
     51 
    4152#define THIS_FILE       "os_core_win32.c" 
    4253 
     
    905916    PJ_ASSERT_RETURN(mutex, PJ_EINVAL); 
    906917 
    907     PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is waiting",  
     918    LOG_MUTEX((mutex->obj_name, "Mutex: thread %s is waiting",  
    908919                                pj_thread_this()->obj_name)); 
    909920 
     
    918929 
    919930#endif 
    920     PJ_LOG(6,(mutex->obj_name,  
     931    LOG_MUTEX((mutex->obj_name,  
    921932              (status==PJ_SUCCESS ? "Mutex acquired by thread %s" : "FAILED by %s"), 
    922933              pj_thread_this()->obj_name)); 
     
    949960#endif 
    950961 
    951     PJ_LOG(6,(mutex->obj_name, "Mutex released by thread %s",  
     962    LOG_MUTEX((mutex->obj_name, "Mutex released by thread %s",  
    952963                                pj_thread_this()->obj_name)); 
    953964 
     
    972983    PJ_ASSERT_RETURN(mutex, PJ_EINVAL); 
    973984 
    974     PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is trying",  
     985    LOG_MUTEX((mutex->obj_name, "Mutex: thread %s is trying",  
    975986                                pj_thread_this()->obj_name)); 
    976987 
     
    982993#endif 
    983994    if (status==PJ_SUCCESS) { 
    984         PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s",  
     995        LOG_MUTEX((mutex->obj_name, "Mutex acquired by thread %s",  
    985996                                  pj_thread_this()->obj_name)); 
    986997 
     
    9901001#endif 
    9911002    } else { 
    992         PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s's trylock() failed",  
     1003        LOG_MUTEX((mutex->obj_name, "Mutex: thread %s's trylock() failed",  
    9931004                                    pj_thread_this()->obj_name)); 
    9941005    } 
     
    10051016    PJ_ASSERT_RETURN(mutex, PJ_EINVAL); 
    10061017 
    1007     PJ_LOG(6,(mutex->obj_name, "Mutex destroyed")); 
     1018    LOG_MUTEX((mutex->obj_name, "Mutex destroyed")); 
    10081019 
    10091020#if PJ_WIN32_WINNT >= 0x0400 
     
    10161027} 
    10171028 
     1029/* 
     1030 * pj_mutex_is_locked() 
     1031 */ 
     1032PJ_DEF(pj_bool_t) pj_mutex_is_locked(pj_mutex_t *mutex) 
     1033{ 
    10181034#if PJ_DEBUG 
    1019 /* 
    1020  * pj_mutex_is_locked() 
    1021  */ 
    1022 PJ_DEF(pj_bool_t) pj_mutex_is_locked(pj_mutex_t *mutex) 
    1023 { 
    10241035    return mutex->owner == pj_thread_this(); 
    1025 } 
    1026 #endif 
     1036#else 
     1037    pj_assert(!"PJ_DEBUG is not set!"); 
     1038    return 1; 
     1039#endif 
     1040} 
    10271041 
    10281042/////////////////////////////////////////////////////////////////////////////// 
     
    10831097    } 
    10841098 
    1085     PJ_LOG(6, (sem->obj_name, "Semaphore created")); 
     1099    LOG_MUTEX((sem->obj_name, "Semaphore created")); 
    10861100 
    10871101    *sem_ptr = sem; 
     
    10961110    PJ_ASSERT_RETURN(sem, PJ_EINVAL); 
    10971111 
    1098     PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s is waiting",  
     1112    LOG_MUTEX((sem->obj_name, "Semaphore: thread %s is waiting",  
    10991113                              pj_thread_this()->obj_name)); 
    11001114 
    11011115    result = WaitForSingleObject(sem->hSemaphore, timeout); 
    11021116    if (result == WAIT_OBJECT_0) { 
    1103         PJ_LOG(6, (sem->obj_name, "Semaphore acquired by thread %s",  
     1117        LOG_MUTEX((sem->obj_name, "Semaphore acquired by thread %s",  
    11041118                                  pj_thread_this()->obj_name)); 
    11051119    } else { 
    1106         PJ_LOG(6, (sem->obj_name, "Semaphore: thread %s FAILED to acquire",  
     1120        LOG_MUTEX((sem->obj_name, "Semaphore: thread %s FAILED to acquire",  
    11071121                                  pj_thread_this()->obj_name)); 
    11081122    } 
     
    11461160    PJ_ASSERT_RETURN(sem, PJ_EINVAL); 
    11471161 
    1148     PJ_LOG(6, (sem->obj_name, "Semaphore released by thread %s", 
     1162    LOG_MUTEX((sem->obj_name, "Semaphore released by thread %s", 
    11491163                              pj_thread_this()->obj_name)); 
    11501164 
     
    11631177    PJ_ASSERT_RETURN(sem, PJ_EINVAL); 
    11641178 
    1165     PJ_LOG(6, (sem->obj_name, "Semaphore destroyed by thread %s", 
     1179    LOG_MUTEX((sem->obj_name, "Semaphore destroyed by thread %s", 
    11661180                              pj_thread_this()->obj_name)); 
    11671181 
Note: See TracChangeset for help on using the changeset viewer.