summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNanang Izzuddin <nanang@teluu.com>2011-12-28 09:49:24 +0000
committerNanang Izzuddin <nanang@teluu.com>2011-12-28 09:49:24 +0000
commit0566586af9552967c1c2d3345542fc2c85976fc3 (patch)
treee21ccfc081ea742a83eab1b44f5c2b86a2050df7
parenta9ced05688bf5a1a8c8280e9476fc83e8fe3805e (diff)
Close #1434: Added PJSUA_LOCK_IS_LOCKED().
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3928 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsua-lib/pjsua_internal.h39
1 files changed, 35 insertions, 4 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h
index 31447ddf..ec236197 100644
--- a/pjsip/include/pjsua-lib/pjsua_internal.h
+++ b/pjsip/include/pjsua-lib/pjsua_internal.h
@@ -366,6 +366,8 @@ struct pjsua_data
pj_caching_pool cp; /**< Global pool factory. */
pj_pool_t *pool; /**< pjsua's private pool. */
pj_mutex_t *mutex; /**< Mutex protection for this data */
+ unsigned mutex_nesting_level; /**< Mutex nesting level. */
+ pj_thread_t *mutex_owner; /**< Mutex owner. */
pjsua_state state; /**< Library state. */
/* Logging: */
@@ -502,13 +504,42 @@ PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
#if 1
-#define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex)
-#define PJSUA_TRY_LOCK() pj_mutex_trylock(pjsua_var.mutex)
-#define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex)
+
+PJ_INLINE(void) PJSUA_LOCK()
+{
+ pj_mutex_lock(pjsua_var.mutex);
+ pjsua_var.mutex_owner = pj_thread_this();
+ ++pjsua_var.mutex_nesting_level;
+}
+
+PJ_INLINE(void) PJSUA_UNLOCK()
+{
+ if (--pjsua_var.mutex_nesting_level == 0)
+ pjsua_var.mutex_owner = NULL;
+ pj_mutex_unlock(pjsua_var.mutex);
+}
+
+PJ_INLINE(pj_status_t) PJSUA_TRY_LOCK()
+{
+ pj_status_t status;
+ status = pj_mutex_trylock(pjsua_var.mutex);
+ if (status == PJ_SUCCESS) {
+ pjsua_var.mutex_owner = pj_thread_this();
+ ++pjsua_var.mutex_nesting_level;
+ }
+ return status;
+}
+
+PJ_INLINE(pj_bool_t) PJSUA_LOCK_IS_LOCKED()
+{
+ return pjsua_var.mutex_owner == pj_thread_this();
+}
+
#else
#define PJSUA_LOCK()
-#define PJSUA_TRY_LOCK() PJ_SUCCESS
+#define PJSUA_TRY_LOCK() PJ_SUCCESS
#define PJSUA_UNLOCK()
+#define PJSUA_LOCK_IS_LOCKED() PJ_TRUE
#endif
/* Core */