From 63147d55f091ec8ba1a5b57cb04b421938ec9fde Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 3 Jul 2006 14:18:17 +0000 Subject: Fixed minor bug in pool_caching.c that prevent pool from being reused if the capacity has changed when the pool is released git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@581 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsip/sip_config.h | 10 ++++++++++ pjsip/src/pjsip/sip_endpoint.c | 24 +++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'pjsip') diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h index 608550ce..535f6697 100644 --- a/pjsip/include/pjsip/sip_config.h +++ b/pjsip/include/pjsip/sip_config.h @@ -120,6 +120,16 @@ #endif +/** + * Allow SIP modules removal or insertions during operation? + * If yes, then locking will be employed when endpoint need to + * access module. + */ +#ifndef PJSIP_SAFE_MODULE +# define PJSIP_SAFE_MODULE 1 +#endif + + /* Endpoint. */ #define PJSIP_MAX_TIMER_COUNT (2*PJSIP_MAX_TSX_COUNT + 2*PJSIP_MAX_DIALOG_COUNT) diff --git a/pjsip/src/pjsip/sip_endpoint.c b/pjsip/src/pjsip/sip_endpoint.c index ba8967a9..940fdf16 100644 --- a/pjsip/src/pjsip/sip_endpoint.c +++ b/pjsip/src/pjsip/sip_endpoint.c @@ -88,6 +88,15 @@ struct pjsip_endpoint }; +#if defined(PJSIP_SAFE_MODULE) && PJSIP_SAFE_MODULE!=0 +# define LOCK_MODULE_ACCESS(ept) pj_rwmutex_lock_read(ept->mod_mutex) +# define UNLOCK_MODULE_ACCESS(ept) pj_rwmutex_unlock_read(ept->mod_mutex) +#else +# define LOCK_MODULE_ACCESS(endpt) +# define UNLOCK_MODULE_ACCESS(endpt) +#endif + + /* * Prototypes. @@ -581,9 +590,14 @@ PJ_DEF(void) pjsip_endpt_release_pool( pjsip_endpoint *endpt, pj_pool_t *pool ) { PJ_LOG(6, (THIS_FILE, "Releasing pool %s", pj_pool_getobjname(pool))); - pj_mutex_lock(endpt->mutex); + /* Don't need to acquire mutex since pool factory is thread safe + pj_mutex_lock(endpt->mutex); + */ pj_pool_release( pool ); + + /* pj_mutex_unlock(endpt->mutex); + */ } @@ -776,7 +790,7 @@ static void endpt_on_rx_msg( pjsip_endpoint *endpt, /* Distribute to modules, starting from modules with highest priority */ - pj_rwmutex_lock_read(endpt->mod_mutex); + LOCK_MODULE_ACCESS(endpt); if (msg->type == PJSIP_REQUEST_MSG) { pjsip_module *mod; @@ -823,7 +837,7 @@ static void endpt_on_rx_msg( pjsip_endpoint *endpt, } } - pj_rwmutex_unlock_read(endpt->mod_mutex); + UNLOCK_MODULE_ACCESS(endpt); /* Must clear mod_data before returning rdata to transport, since * rdata may be reused. @@ -842,7 +856,7 @@ static pj_status_t endpt_on_tx_msg( pjsip_endpoint *endpt, pjsip_module *mod; /* Distribute to modules, starting from modules with LOWEST priority */ - pj_rwmutex_lock_read(endpt->mod_mutex); + LOCK_MODULE_ACCESS(endpt); mod = endpt->module_list.prev; if (tdata->msg->type == PJSIP_REQUEST_MSG) { @@ -864,7 +878,7 @@ static pj_status_t endpt_on_tx_msg( pjsip_endpoint *endpt, } } - pj_rwmutex_unlock_read(endpt->mod_mutex); + UNLOCK_MODULE_ACCESS(endpt); return status; } -- cgit v1.2.3