[asterisk-commits] file: branch 1.4 r51788 - /branches/1.4/channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 23 15:46:31 MST 2007


Author: file
Date: Tue Jan 23 16:46:31 2007
New Revision: 51788

URL: http://svn.digium.com/view/asterisk?view=rev&rev=51788
Log:
Update channel drivers to use module referencing so that unloading them while in use will not result in crashes. (issue #8897 reported by junky)

Modified:
    branches/1.4/channels/chan_alsa.c
    branches/1.4/channels/chan_features.c
    branches/1.4/channels/chan_gtalk.c
    branches/1.4/channels/chan_iax2.c
    branches/1.4/channels/chan_oss.c
    branches/1.4/channels/chan_phone.c
    branches/1.4/channels/chan_sip.c
    branches/1.4/channels/chan_skinny.c
    branches/1.4/channels/chan_zap.c

Modified: branches/1.4/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_alsa.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_alsa.c (original)
+++ branches/1.4/channels/chan_alsa.c Tue Jan 23 16:46:31 2007
@@ -113,11 +113,9 @@
 static struct timeval lasttime;
 #endif
 
-static int usecnt;
 static int silencesuppression = 0;
 static int silencethreshold = 1000;
 
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 AST_MUTEX_DEFINE_STATIC(alsalock);
 
 static const char tdesc[] = "ALSA Console Channel Driver";
@@ -573,9 +571,7 @@
 	c->tech_pvt = NULL;
 	alsa.owner = NULL;
 	ast_verbose(" << Hangup on console >> \n");
-	ast_mutex_lock(&usecnt_lock);
-	usecnt--;
-	ast_mutex_unlock(&usecnt_lock);
+	ast_module_unref(ast_module_info->self);
 	if (hookstate) {
 		hookstate = 0;
 		if (!autoanswer) {
@@ -800,10 +796,7 @@
 	if (!ast_strlen_zero(language))
 		ast_string_field_set(tmp, language, language);
 	p->owner = tmp;
-	ast_mutex_lock(&usecnt_lock);
-	usecnt++;
-	ast_mutex_unlock(&usecnt_lock);
-	ast_update_use_count();
+	ast_module_ref(ast_module_info->self);
 	ast_jb_configure(tmp, &global_jbconf);
 	if (state != AST_STATE_DOWN) {
 		if (ast_pbx_start(tmp)) {

Modified: branches/1.4/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_features.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_features.c (original)
+++ branches/1.4/channels/chan_features.c Tue Jan 23 16:46:31 2007
@@ -64,9 +64,6 @@
 #include "asterisk/stringfields.h"
 
 static const char tdesc[] = "Feature Proxy Channel Driver";
-
-static int usecnt =0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
 #define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
 
@@ -492,10 +489,7 @@
 	p->subs[index].owner = tmp;
 	if (!p->owner)
 		p->owner = tmp;
-	ast_mutex_lock(&usecnt_lock);
-	usecnt++;
-	ast_mutex_unlock(&usecnt_lock);
-	ast_update_use_count();
+	ast_module_ref(ast_module_info->self);
 	return tmp;
 }
 

Modified: branches/1.4/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_gtalk.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_gtalk.c (original)
+++ branches/1.4/channels/chan_gtalk.c Tue Jan 23 16:46:31 2007
@@ -163,9 +163,6 @@
 };
 
 static const char desc[] = "Gtalk Channel";
-
-static int usecnt = 0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
 static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
 
@@ -953,9 +950,7 @@
 	if (!ast_strlen_zero(client->musicclass))
 		ast_string_field_set(tmp, musicclass, client->musicclass);
 	i->owner = tmp;
-	ast_mutex_lock(&usecnt_lock);
-	usecnt++;
-	ast_mutex_unlock(&usecnt_lock);
+	ast_module_ref(ast_module_info->self);
 	ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
 	ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
 	/* Don't use ast_set_callerid() here because it will
@@ -1467,9 +1462,7 @@
 	ast_mutex_unlock(&p->lock);
 
 	gtalk_free_pvt(client, p);
-	ast_mutex_lock(&usecnt_lock);
-	usecnt--;
-	ast_mutex_unlock(&usecnt_lock);
+	ast_module_unref(ast_module_info->self);
 
 	return 0;
 }

Modified: branches/1.4/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_iax2.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_iax2.c (original)
+++ branches/1.4/channels/chan_iax2.c Tue Jan 23 16:46:31 2007
@@ -172,8 +172,6 @@
 
 static struct ast_netsock_list *netsock;
 static int defaultsockfd = -1;
-
-static int usecnt = 0;
 
 int (*iax2_regfunk)(const char *username, int onoff) = NULL;
 
@@ -1716,8 +1714,7 @@
 		c->tech_pvt = NULL;
 		ast_queue_hangup(c);
 		pvt->owner = NULL;
-		ast_atomic_fetchadd_int(&usecnt, -1);
-		ast_update_use_count();
+		ast_module_unref(ast_module_info->self);
 	}
 	return 0;
 }
@@ -3302,8 +3299,7 @@
 	for (v = i->vars ; v ; v = v->next)
 		pbx_builtin_setvar_helper(tmp, v->name, v->value);
 
-	ast_atomic_fetchadd_int(&usecnt, 1);
-	ast_update_use_count();
+	ast_module_ref(ast_module_info->self);
 	
 	return tmp;
 }

Modified: branches/1.4/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_oss.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_oss.c (original)
+++ branches/1.4/channels/chan_oss.c Tue Jan 23 16:46:31 2007
@@ -280,10 +280,6 @@
 #ifndef MAX
 #define MAX(a,b) ((a) > (b) ? (a) : (b))
 #endif
-
-
-static int usecnt;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
 static char *config = "oss.conf";	/* default config file */
 
@@ -842,9 +838,7 @@
 	c->tech_pvt = NULL;
 	o->owner = NULL;
 	ast_verbose(" << Hangup on console >> \n");
-	ast_mutex_lock(&usecnt_lock);	/* XXX not sure why */
-	usecnt--;
-	ast_mutex_unlock(&usecnt_lock);
+	ast_module_unref(ast_module_info->self);
 	if (o->hookstate) {
 		if (o->autoanswer || o->autohangup) {
 			/* Assume auto-hangup too */
@@ -1025,10 +1019,7 @@
 		c->cid.cid_dnid = ast_strdup(ext);
 
 	o->owner = c;
-	ast_mutex_lock(&usecnt_lock);
-	usecnt++;
-	ast_mutex_unlock(&usecnt_lock);
-	ast_update_use_count();
+	ast_module_ref(ast_module_info->self);
 	ast_jb_configure(c, &global_jbconf);
 	if (state != AST_STATE_DOWN) {
 		if (ast_pbx_start(c)) {

Modified: branches/1.4/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_phone.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_phone.c (original)
+++ branches/1.4/channels/chan_phone.c Tue Jan 23 16:46:31 2007
@@ -93,15 +93,12 @@
 
 /* Default language */
 static char language[MAX_LANGUAGE] = "";
-static int usecnt =0;
 
 static int echocancel = AEC_OFF;
 
 static int silencesupression = 0;
 
 static int prefformat = AST_FORMAT_G723_1 | AST_FORMAT_SLINEAR | AST_FORMAT_ULAW;
-
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
 /* Protect the interface list (of phone_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
@@ -385,12 +382,7 @@
 	p->dialtone = 0;
 	memset(p->ext, 0, sizeof(p->ext));
 	((struct phone_pvt *)(ast->tech_pvt))->owner = NULL;
-	ast_mutex_lock(&usecnt_lock);
-	usecnt--;
-	if (usecnt < 0) 
-		ast_log(LOG_WARNING, "Usecnt < 0???\n");
-	ast_mutex_unlock(&usecnt_lock);
-	ast_update_use_count();
+	ast_module_unref(ast_module_info->self);
 	if (option_verbose > 2) 
 		ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
 	ast->tech_pvt = NULL;
@@ -877,10 +869,7 @@
 		tmp->cid.cid_name = ast_strdup(i->cid_name);
 
 		i->owner = tmp;
-		ast_mutex_lock(&usecnt_lock);
-		usecnt++;
-		ast_mutex_unlock(&usecnt_lock);
-		ast_update_use_count();
+		ast_module_ref(ast_module_info->self);
 		if (state != AST_STATE_DOWN) {
 			if (state == AST_STATE_RING) {
 				ioctl(tmp->fds[0], PHONE_RINGBACK);
@@ -960,10 +949,7 @@
 			if (i->mode == MODE_IMMEDIATE) {
 				phone_new(i, AST_STATE_RING, i->context);
 			} else if (i->mode == MODE_DIALTONE) {
-				ast_mutex_lock(&usecnt_lock);
-				usecnt++;
-				ast_mutex_unlock(&usecnt_lock);
-				ast_update_use_count();
+				ast_module_ref(ast_module_info->self);
 				/* Reset the extension */
 				i->ext[0] = '\0';
 				/* Play the dialtone */
@@ -973,10 +959,7 @@
 				ioctl(i->fd, PHONE_PLAY_START);
 				i->lastformat = -1;
 			} else if (i->mode == MODE_SIGMA) {
-				ast_mutex_lock(&usecnt_lock);
-				usecnt++;
-				ast_mutex_unlock(&usecnt_lock);
-				ast_update_use_count();
+				ast_module_ref(ast_module_info->self);
 				/* Reset the extension */
 				i->ext[0] = '\0';
 				/* Play the dialtone */
@@ -984,12 +967,8 @@
 				ioctl(i->fd, PHONE_DIALTONE);
 			}
 		} else {
-			if (i->dialtone) {
-				ast_mutex_lock(&usecnt_lock);
-				usecnt--;
-				ast_mutex_unlock(&usecnt_lock);
-				ast_update_use_count();
-			}
+			if (i->dialtone)
+				ast_module_unref(ast_module_info->self);
 			memset(i->ext, 0, sizeof(i->ext));
 			if (i->cpt)
 			{

Modified: branches/1.4/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_sip.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_sip.c (original)
+++ branches/1.4/channels/chan_sip.c Tue Jan 23 16:46:31 2007
@@ -221,8 +221,6 @@
 
 static const char config[] = "sip.conf";
 static const char notify_config[] = "sip_notify.conf";
-static int usecnt = 0;
-
 
 #define RTP 	1
 #define NO_RTP	0
@@ -3324,8 +3322,7 @@
 	p->owner = NULL;
 	ast->tech_pvt = NULL;
 
-	ast_atomic_fetchadd_int(&usecnt, -1);
-	ast_update_use_count();
+	ast_module_unref(ast_module_info->self);
 
 	/* Do not destroy this pvt until we have timeout or
 	   get an answer to the BYE or INVITE/CANCEL 
@@ -3852,8 +3849,7 @@
 	if (!ast_strlen_zero(i->language))
 		ast_string_field_set(tmp, language, i->language);
 	i->owner = tmp;
-	ast_atomic_fetchadd_int(&usecnt, 1);
-	ast_update_use_count();
+	ast_module_ref(ast_module_info->self);
 	ast_copy_string(tmp->context, i->context, sizeof(tmp->context));
 	ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
 

Modified: branches/1.4/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_skinny.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_skinny.c (original)
+++ branches/1.4/channels/chan_skinny.c Tue Jan 23 16:46:31 2007
@@ -867,10 +867,6 @@
 /* driver scheduler */
 static struct sched_context *sched;
 static struct io_context *io;
-
-/* usage count and locking */
-static int usecnt = 0;
-AST_MUTEX_DEFINE_STATIC(usecnt_lock);
 
 /* Protect the monitoring thread, so only one process can kill or start it, and not
    when it's doing something critical. */
@@ -2754,10 +2750,7 @@
 		if (l->amaflags)
 			tmp->amaflags = l->amaflags;
 
-		ast_mutex_lock(&usecnt_lock);
-		usecnt++;
-		ast_mutex_unlock(&usecnt_lock);
-		ast_update_use_count();
+		ast_module_ref(ast_module_info->self);
 		tmp->callgroup = l->callgroup;
 		tmp->pickupgroup = l->pickupgroup;
 		ast_string_field_set(tmp, call_forward, l->call_forward);

Modified: branches/1.4/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_zap.c?view=diff&rev=51788&r1=51787&r2=51788
==============================================================================
--- branches/1.4/channels/chan_zap.c (original)
+++ branches/1.4/channels/chan_zap.c Tue Jan 23 16:46:31 2007
@@ -228,8 +228,6 @@
 
 /*! \brief How long to wait for an extra digit, if there is an ambiguous match */
 static int matchdigittimeout = 3000;
-
-static int usecnt = 0;
 
 /*! \brief Protect the interface list (of zt_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
@@ -2703,8 +2701,7 @@
 	p->oprmode = 0;
 	ast->tech_pvt = NULL;
 	ast_mutex_unlock(&p->lock);
-	ast_atomic_fetchadd_int(&usecnt, -1);
-	ast_update_use_count();
+	ast_module_unref(ast_module_info->self);
 	if (option_verbose > 2) 
 		ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
 
@@ -5324,8 +5321,7 @@
 		}
 	}
 
-	ast_atomic_fetchadd_int(&usecnt, 1);
-	ast_update_use_count();
+	ast_module_ref(ast_module_info->self);
 	
 	return tmp;
 }



More information about the asterisk-commits mailing list