summaryrefslogtreecommitdiff
path: root/pjsip/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-09-19 13:37:53 +0000
committerBenny Prijono <bennylp@teluu.com>2006-09-19 13:37:53 +0000
commit4b188d682a36a7fa454884ca55b5cf5a7bad069c (patch)
treec7f94ec4bd11263869fc2ed8804a7864a93a0591 /pjsip/include
parentcf81bc0a2ab2947f4a2c5c5fd20bc77ea5611947 (diff)
Fixed race-condition/deadlock problems in the dialog/user agent layer
all the way up to PJSUA-API: - standardized locking order: dialog then user agent, and dialog then PJSUA - any threads that attempt to acquire mutexes in different order than above MUST employ retry mechanism (for an example, see acquire_call() in pjsua_call.c). This retry mechanism has also been used in the UA layer (sip_ua_layer.c) since it needs to lock user agent layer first before the dialog. - introduced pjsip_dlg_try_inc_lock() and PJSUA_TRY_LOCK() to accomodate above. - pjsua tested on Quad Xeon with 4 threads and 200 cps, so far so good. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@729 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip/include')
-rw-r--r--pjsip/include/pjsip/sip_dialog.h10
-rw-r--r--pjsip/include/pjsip/sip_ua_layer.h18
-rw-r--r--pjsip/include/pjsua-lib/pjsua_internal.h8
3 files changed, 15 insertions, 21 deletions
diff --git a/pjsip/include/pjsip/sip_dialog.h b/pjsip/include/pjsip/sip_dialog.h
index 191196a5..b4d2a1ac 100644
--- a/pjsip/include/pjsip/sip_dialog.h
+++ b/pjsip/include/pjsip/sip_dialog.h
@@ -356,6 +356,16 @@ PJ_DECL(void*) pjsip_dlg_get_mod_data( pjsip_dialog *dlg,
PJ_DECL(void) pjsip_dlg_inc_lock( pjsip_dialog *dlg );
/**
+ * Try to acquire dialog's lock, but return immediately if lock can not
+ * be acquired.
+ *
+ * @param dlg The dialog.
+ *
+ * @return PJ_SUCCESS if lock has been acquired.
+ */
+PJ_DECL(pj_status_t) pjsip_dlg_try_inc_lock( pjsip_dialog *dlg );
+
+/**
* Unlock dialog and decrement temporary session counter. After this function
* is called, dialog may be destroyed.
*
diff --git a/pjsip/include/pjsip/sip_ua_layer.h b/pjsip/include/pjsip/sip_ua_layer.h
index 08e692ca..c4e2d7c7 100644
--- a/pjsip/include/pjsip/sip_ua_layer.h
+++ b/pjsip/include/pjsip/sip_ua_layer.h
@@ -81,24 +81,6 @@ PJ_DECL(pjsip_user_agent*) pjsip_ua_instance(void);
/**
- * Lock the dialog's hash table. This function is normally called by
- * dialog code only.
- *
- * @return PJ_SUCCESS on success or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsip_ua_lock_dlg_table(void);
-
-
-/**
- * Unlock the dialog's hash table. This function is normally called by
- * dialog code only.
- *
- * @return PJ_SUCCESS on success or the appropriate error code.
- */
-PJ_DECL(pj_status_t) pjsip_ua_unlock_dlg_table(void);
-
-
-/**
* Destroy the user agent layer.
*
* @return PJ_SUCCESS on success.
diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h
index 8b1002b4..10e76635 100644
--- a/pjsip/include/pjsua-lib/pjsua_internal.h
+++ b/pjsip/include/pjsua-lib/pjsua_internal.h
@@ -257,11 +257,13 @@ PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool,
}
-#if 0
-#define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex);
-#define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex);
+#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)
#else
#define PJSUA_LOCK()
+#define PJSUA_TRY_LOCK() PJ_SUCCESS
#define PJSUA_UNLOCK()
#endif