summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-03-05 21:08:01 +0000
committerBenny Prijono <bennylp@teluu.com>2007-03-05 21:08:01 +0000
commit0e8c7ebc65e2f5f59149fcd3ce63de4675d7c3d2 (patch)
treeb0eed51495dafa67b5c82697b16904ee28c5012a
parent837c92b0337f44eac5469411a454e3188dbe2574 (diff)
Optimization on the log and add tracing on mutex trylock
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1042 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjlib/include/pj/log.h10
-rw-r--r--pjlib/src/pj/log.c10
-rw-r--r--pjlib/src/pj/os_core_unix.c6
-rw-r--r--pjlib/src/pj/os_core_win32.c7
4 files changed, 28 insertions, 5 deletions
diff --git a/pjlib/include/pj/log.h b/pjlib/include/pj/log.h
index c6622590..4d28abec 100644
--- a/pjlib/include/pj/log.h
+++ b/pjlib/include/pj/log.h
@@ -98,7 +98,10 @@ enum pj_log_decoration
\endverbatim
* @hideinitializer
*/
-#define PJ_LOG(level,arg) pj_log_wrapper_##level(arg)
+#define PJ_LOG(level,arg) do { \
+ if (level <= pj_log_get_level()) \
+ pj_log_wrapper_##level(arg); \
+ } while (0)
/**
* Signature for function to be registered to the logging subsystem to
@@ -171,7 +174,12 @@ PJ_DECL(void) pj_log_set_level(int level);
*
* @return Current log maximum level.
*/
+#if 0
PJ_DECL(int) pj_log_get_level(void);
+#else
+PJ_DECL(int) pj_log_max_level;
+#define pj_log_get_level() pj_log_max_level
+#endif
/**
* Set log decoration. The log decoration flag controls what are printed
diff --git a/pjlib/src/pj/log.c b/pjlib/src/pj/log.c
index 18c6ef45..bc395546 100644
--- a/pjlib/src/pj/log.c
+++ b/pjlib/src/pj/log.c
@@ -24,7 +24,7 @@
#if PJ_LOG_MAX_LEVEL >= 1
-static int log_max_level = PJ_LOG_MAX_LEVEL;
+PJ_DEF(int) pj_log_max_level = PJ_LOG_MAX_LEVEL;
static pj_log_func *log_writer = &pj_log_write;
static unsigned log_decor = PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC |
PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE;
@@ -45,13 +45,15 @@ PJ_DEF(unsigned) pj_log_get_decor(void)
PJ_DEF(void) pj_log_set_level(int level)
{
- log_max_level = level;
+ pj_log_max_level = level;
}
+#if 0
PJ_DEF(int) pj_log_get_level(void)
{
- return log_max_level;
+ return pj_log_max_level;
}
+#endif
PJ_DEF(void) pj_log_set_log_func( pj_log_func *func )
{
@@ -76,7 +78,7 @@ PJ_DEF(void) pj_log( const char *sender, int level,
PJ_CHECK_STACK();
- if (level > log_max_level)
+ if (level > pj_log_max_level)
return;
/* Get current date/time. */
diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c
index a28af657..0dbe0afe 100644
--- a/pjlib/src/pj/os_core_unix.c
+++ b/pjlib/src/pj/os_core_unix.c
@@ -1123,6 +1123,9 @@ PJ_DEF(pj_status_t) pj_mutex_trylock(pj_mutex_t *mutex)
PJ_CHECK_STACK();
PJ_ASSERT_RETURN(mutex, PJ_EINVAL);
+ PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is trying",
+ pj_thread_this()->obj_name));
+
status = pthread_mutex_trylock( &mutex->mutex );
if (status==0) {
@@ -1138,6 +1141,9 @@ PJ_DEF(pj_status_t) pj_mutex_trylock(pj_mutex_t *mutex)
PJ_LOG(6,(mutex->obj_name, "Mutex acquired by thread %s",
pj_thread_this()->obj_name));
#endif
+ } else {
+ PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s's trylock() failed",
+ pj_thread_this()->obj_name));
}
if (status==0)
diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c
index 5c8d93b5..81737981 100644
--- a/pjlib/src/pj/os_core_win32.c
+++ b/pjlib/src/pj/os_core_win32.c
@@ -885,6 +885,9 @@ PJ_DEF(pj_status_t) pj_mutex_trylock(pj_mutex_t *mutex)
PJ_CHECK_STACK();
PJ_ASSERT_RETURN(mutex, PJ_EINVAL);
+ PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s is trying",
+ pj_thread_this()->obj_name));
+
#if PJ_WIN32_WINNT >= 0x0400
status=TryEnterCriticalSection(&mutex->crit) ? PJ_SUCCESS : PJ_EUNKNOWN;
#else
@@ -899,7 +902,11 @@ PJ_DEF(pj_status_t) pj_mutex_trylock(pj_mutex_t *mutex)
mutex->owner = pj_thread_this();
++mutex->nesting_level;
#endif
+ } else {
+ PJ_LOG(6,(mutex->obj_name, "Mutex: thread %s's trylock() failed",
+ pj_thread_this()->obj_name));
}
+
return status;
}