From a883b6b13b67898accdc1ffe3fd9e770612352b1 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Tue, 3 Feb 2015 13:17:09 +0100 Subject: Improve logging Change-Id: Iabfe272e95e4f3517f3072dd6c36b8889c2fdbd1 --- sal/osl/unx/conditn.cxx | 111 ++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 75 deletions(-) diff --git a/sal/osl/unx/conditn.cxx b/sal/osl/unx/conditn.cxx index 91d80d75ed5b..42aa05ef5194 100644 --- a/sal/osl/unx/conditn.cxx +++ b/sal/osl/unx/conditn.cxx @@ -37,14 +37,13 @@ typedef struct _oslConditionImpl oslCondition SAL_CALL osl_createCondition() { - oslConditionImpl* pCond; + oslConditionImpl* pCond; int nRet=0; pCond = (oslConditionImpl*) malloc(sizeof(oslConditionImpl)); if ( pCond == 0 ) { - SAL_WARN("sal.osl", "std::bad_alloc in C"); return 0; } @@ -54,10 +53,7 @@ oslCondition SAL_CALL osl_createCondition() nRet = pthread_cond_init(&pCond->m_Condition, PTHREAD_CONDATTR_DEFAULT); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", - "pthread_cond_init failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "pthread_cond_init failed: " << strerror(nRet) ); free(pCond); return 0; @@ -66,21 +62,17 @@ oslCondition SAL_CALL osl_createCondition() nRet = pthread_mutex_init(&pCond->m_Lock, PTHREAD_MUTEXATTR_DEFAULT); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", - "pthread_mutex_init failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "pthread_mutex_init failed: " << strerror(nRet) ); nRet = pthread_cond_destroy(&pCond->m_Condition); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_cond_destroy failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "pthread_cond_destroy failed: " << strerror(nRet) ); free(pCond); pCond = 0; } + SAL_INFO( "osl.condition", "osl_createCondition(): " << pCond ); + return (oslCondition)pCond; } @@ -88,20 +80,16 @@ void SAL_CALL osl_destroyCondition(oslCondition Condition) { oslConditionImpl* pCond; - if ( Condition ) - { - pCond = (oslConditionImpl*)Condition; + pCond = (oslConditionImpl*)Condition; + + SAL_INFO( "osl.condition", "osl_destroyCondition(" << pCond << ")" ); + if ( pCond ) + { int nRet = pthread_cond_destroy(&pCond->m_Condition); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_cond_destroy failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "pthread_cond_destroy failed: " << strerror(nRet) ); nRet = pthread_mutex_destroy(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_mutex_destroy failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "pthread_mutex_destroy failed: " << strerror(nRet) ); free(Condition); } @@ -125,10 +113,7 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) nRet = pthread_mutex_lock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", - "pthread_mutex_lock failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "osl_setCondition(" << pCond << "): pthread_mutex_lock failed: " << strerror(nRet) ); return sal_False; } @@ -136,10 +121,7 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) nRet = pthread_cond_broadcast(&pCond->m_Condition); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", - "pthread_cond_broadcast failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "osl_setCondition(" << pCond << "): pthread_cond_broadcast failed: " << strerror(nRet) ); // try to unlock the mutex pthread_mutex_unlock(&pCond->m_Lock); return sal_False; @@ -148,13 +130,12 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) nRet = pthread_mutex_unlock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", - "pthread_mutex_unlock failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "osl_setCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); return sal_False; } + SAL_INFO( "osl.condition", "osl_setCondition(" << pCond << ")" ); + return sal_True; } @@ -176,10 +157,7 @@ sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition) nRet = pthread_mutex_lock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", - "pthread_mutex_lock failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "osl_resetCondition(" << pCond << "): pthread_mutex_lock failed: " << strerror(nRet) ); return sal_False; } @@ -188,12 +166,12 @@ sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition) nRet = pthread_mutex_unlock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", "pthread_mutex_unlock failed, errno " << nRet <<", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "osl_resetCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); return sal_False; } + SAL_INFO( "osl.condition", "osl_resetCondition(" << pCond << ")" ); + return sal_True; } @@ -206,6 +184,8 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time assert(Condition); pCond = (oslConditionImpl*)Condition; + SAL_INFO( "osl.condition", "osl_waitCondition(" << pCond << ")" ); + if ( pCond == 0 ) { return osl_cond_result_error; @@ -214,9 +194,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time nRet = pthread_mutex_lock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", "pthread_mutex_lock failed, errno " << nRet <<", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_lock failed: " << strerror(nRet) ); return osl_cond_result_error; } @@ -242,10 +220,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time { Result = osl_cond_result_timeout; nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_mutex_unlock failed, errno " << nRet - << ", \"" << strerror(nRet) << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); return Result; } @@ -253,10 +228,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time { Result = osl_cond_result_error; nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_mutex_unlock failed, errno " << nRet - << ", \"" << strerror(nRet) << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); return Result; } } @@ -271,16 +243,10 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time nRet = pthread_cond_wait(&pCond->m_Condition, &pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( - "sal.osl", - "pthread_cond_wait failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN( "osl.condition", "osl_waitCondition(" << pCond << "): pthread_cond_wait failed: " << strerror(nRet) ); Result = osl_cond_result_error; nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_mutex_unlock failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); return Result; } @@ -288,10 +254,9 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time } nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_mutex_unlock failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + + SAL_INFO( "osl.condition", "osl_waitCondition(" << pCond << "): " << (Result == osl_cond_result_ok ? "OK" : "ERROR") ); return Result; } @@ -311,18 +276,14 @@ sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition) } nRet = pthread_mutex_lock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_mutex_lock failed, errno " << nRet << ", \"" << strerror(nRet) - << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "osl_checkCondition(" << pCond << "): pthread_mutex_lock failed: " << strerror(nRet) ); State = pCond->m_State; nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( - nRet != 0, "sal.osl", - "pthread_mutex_unlock failed, errno " << nRet << ", \"" - << strerror(nRet) << '"'); + SAL_WARN_IF( nRet != 0, "osl.condition", "osl_checkCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + + SAL_INFO( "osl.condition", "osl_checkCondition(" << pCond << "): " << (State ? "YES" : "NO") ); return State; } -- cgit