[asterisk-commits] file: branch file/usecnt-cleanup r54141 - in
/team/file/usecnt-cleanup: chann...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Feb 12 17:10:24 MST 2007
Author: file
Date: Mon Feb 12 18:10:24 2007
New Revision: 54141
URL: http://svn.digium.com/view/asterisk?view=rev&rev=54141
Log:
Move channel technology reference counting to core.
Modified:
team/file/usecnt-cleanup/channels/chan_agent.c
team/file/usecnt-cleanup/channels/chan_alsa.c
team/file/usecnt-cleanup/channels/chan_features.c
team/file/usecnt-cleanup/channels/chan_gtalk.c
team/file/usecnt-cleanup/channels/chan_h323.c
team/file/usecnt-cleanup/channels/chan_iax2.c
team/file/usecnt-cleanup/channels/chan_jingle.c
team/file/usecnt-cleanup/channels/chan_local.c
team/file/usecnt-cleanup/channels/chan_mgcp.c
team/file/usecnt-cleanup/channels/chan_oss.c
team/file/usecnt-cleanup/channels/chan_phone.c
team/file/usecnt-cleanup/channels/chan_sip.c
team/file/usecnt-cleanup/channels/chan_skinny.c
team/file/usecnt-cleanup/channels/chan_zap.c
team/file/usecnt-cleanup/include/asterisk/channel.h
team/file/usecnt-cleanup/main/channel.c
Modified: team/file/usecnt-cleanup/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_agent.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_agent.c (original)
+++ team/file/usecnt-cleanup/channels/chan_agent.c Mon Feb 12 18:10:24 2007
@@ -2455,7 +2455,7 @@
static int load_module(void)
{
/* Make sure we can register our agent channel type */
- if (ast_channel_register(&agent_tech)) {
+ if (ast_channel_register(&agent_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class 'Agent'\n");
return -1;
}
Modified: team/file/usecnt-cleanup/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_alsa.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_alsa.c (original)
+++ team/file/usecnt-cleanup/channels/chan_alsa.c Mon Feb 12 18:10:24 2007
@@ -580,7 +580,6 @@
c->tech_pvt = NULL;
alsa.owner = NULL;
ast_verbose(" << Hangup on console >> \n");
- ast_module_unref(ast_module_info->self);
if (hookstate) {
hookstate = 0;
if (!autoanswer) {
@@ -806,7 +805,6 @@
if (!ast_strlen_zero(language))
ast_string_field_set(tmp, language, language);
p->owner = tmp;
- ast_module_ref(ast_module_info->self);
ast_jb_configure(tmp, &global_jbconf);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
@@ -1136,7 +1134,7 @@
return AST_MODULE_LOAD_DECLINE;
}
- if (ast_channel_register(&alsa_tech)) {
+ if (ast_channel_register(&alsa_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class 'Console'\n");
return AST_MODULE_LOAD_FAILURE;
}
Modified: team/file/usecnt-cleanup/channels/chan_features.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_features.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_features.c (original)
+++ team/file/usecnt-cleanup/channels/chan_features.c Mon Feb 12 18:10:24 2007
@@ -490,7 +490,6 @@
p->subs[index].owner = tmp;
if (!p->owner)
p->owner = tmp;
- ast_module_ref(ast_module_info->self);
return tmp;
}
@@ -543,7 +542,7 @@
static int load_module(void)
{
/* Make sure we can register our sip channel type */
- if (ast_channel_register(&features_tech)) {
+ if (ast_channel_register(&features_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class 'Feature'\n");
return -1;
}
Modified: team/file/usecnt-cleanup/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_gtalk.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_gtalk.c (original)
+++ team/file/usecnt-cleanup/channels/chan_gtalk.c Mon Feb 12 18:10:24 2007
@@ -953,7 +953,6 @@
if (!ast_strlen_zero(client->musicclass))
ast_string_field_set(tmp, musicclass, client->musicclass);
i->owner = tmp;
- 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
@@ -1466,7 +1465,6 @@
ast_mutex_unlock(&p->lock);
gtalk_free_pvt(client, p);
- ast_module_unref(ast_module_info->self);
return 0;
}
@@ -1803,7 +1801,7 @@
ast_cli_register_multiple(gtalk_cli, sizeof(gtalk_cli) / sizeof(gtalk_cli[0]));
/* Make sure we can register our channel type */
- if (ast_channel_register(>alk_tech)) {
+ if (ast_channel_register(>alk_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", gtalk_tech.type);
return -1;
}
Modified: team/file/usecnt-cleanup/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_h323.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_h323.c (original)
+++ team/file/usecnt-cleanup/channels/chan_h323.c Mon Feb 12 18:10:24 2007
@@ -750,9 +750,6 @@
pvt->needdestroy = 1;
ast_mutex_unlock(&pvt->lock);
- /* Update usage counter */
- ast_module_unref(ast_module_info->self);
-
return 0;
}
@@ -1023,8 +1020,6 @@
/* Don't hold a oh323_pvt lock while we allocate a chanel */
ast_mutex_unlock(&pvt->lock);
ch = ast_channel_alloc(1, state, cid_num, cid_name, "H323/%s", host);
- /* Update usage counter */
- ast_module_ref(ast_module_info->self);
ast_mutex_lock(&pvt->lock);
if (ch) {
ch->tech = &oh323_tech;
Modified: team/file/usecnt-cleanup/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_iax2.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_iax2.c (original)
+++ team/file/usecnt-cleanup/channels/chan_iax2.c Mon Feb 12 18:10:24 2007
@@ -1772,7 +1772,6 @@
c->tech_pvt = NULL;
ast_queue_hangup(c);
pvt->owner = NULL;
- ast_module_unref(ast_module_info->self);
}
return 0;
@@ -3407,7 +3406,6 @@
for (v = i->vars ; v ; v = v->next)
pbx_builtin_setvar_helper(tmp, v->name, v->value);
- ast_module_ref(ast_module_info->self);
return tmp;
}
@@ -10154,7 +10152,7 @@
if(set_config(config, 0) == -1)
return AST_MODULE_LOAD_DECLINE;
- if (ast_channel_register(&iax2_tech)) {
+ if (ast_channel_register(&iax2_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", "IAX2");
__unload_module();
return AST_MODULE_LOAD_FAILURE;
Modified: team/file/usecnt-cleanup/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_jingle.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_jingle.c (original)
+++ team/file/usecnt-cleanup/channels/chan_jingle.c Mon Feb 12 18:10:24 2007
@@ -1686,7 +1686,7 @@
ast_rtp_proto_register(&jingle_rtp);
/* Make sure we can register our channel type */
- if (ast_channel_register(&jingle_tech)) {
+ if (ast_channel_register(&jingle_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
return -1;
}
Modified: team/file/usecnt-cleanup/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_local.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_local.c (original)
+++ team/file/usecnt-cleanup/channels/chan_local.c Mon Feb 12 18:10:24 2007
@@ -668,7 +668,7 @@
static int load_module(void)
{
/* Make sure we can register our channel type */
- if (ast_channel_register(&local_tech)) {
+ if (ast_channel_register(&local_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n");
return -1;
}
Modified: team/file/usecnt-cleanup/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_mgcp.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_mgcp.c (original)
+++ team/file/usecnt-cleanup/channels/chan_mgcp.c Mon Feb 12 18:10:24 2007
@@ -988,8 +988,6 @@
sub->rtp = NULL;
}
- ast_module_unref(ast_module_info->self);
-
if ((p->hookstate == MGCP_ONHOOK) && (!sub->next->rtp)) {
p->hidecallerid = 0;
if (p->hascallwaiting && !p->callwaiting) {
@@ -1465,7 +1463,6 @@
if (i->amaflags)
tmp->amaflags = i->amaflags;
sub->owner = tmp;
- ast_module_ref(ast_module_info->self);
tmp->callgroup = i->callgroup;
tmp->pickupgroup = i->pickupgroup;
ast_string_field_set(tmp, call_forward, i->call_forward);
@@ -4272,7 +4269,7 @@
return AST_MODULE_LOAD_DECLINE;
/* Make sure we can register our mgcp channel type */
- if (ast_channel_register(&mgcp_tech)) {
+ if (ast_channel_register(&mgcp_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class 'MGCP'\n");
io_context_destroy(io);
sched_context_destroy(sched);
@@ -4348,7 +4345,7 @@
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
/* We always want to leave this in a consistent state */
- ast_channel_register(&mgcp_tech);
+ ast_channel_register(&mgcp_tech, ast_module_info->self);
mgcp_reloading = 0;
mgcp_reload(0, 0, NULL);
return -1;
@@ -4366,7 +4363,7 @@
} else {
ast_log(LOG_WARNING, "Unable to lock the gateways list.\n");
/* We always want to leave this in a consistent state */
- ast_channel_register(&mgcp_tech);
+ ast_channel_register(&mgcp_tech, ast_module_info->self);
/* Allow the monitor to restart */
monitor_thread = AST_PTHREADT_NULL;
mgcp_reloading = 0;
Modified: team/file/usecnt-cleanup/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_oss.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_oss.c (original)
+++ team/file/usecnt-cleanup/channels/chan_oss.c Mon Feb 12 18:10:24 2007
@@ -865,7 +865,6 @@
c->tech_pvt = NULL;
o->owner = NULL;
ast_verbose(" << Hangup on console >> \n");
- ast_module_unref(ast_module_info->self);
if (o->hookstate) {
if (o->autoanswer || o->autohangup) {
/* Assume auto-hangup too */
@@ -1048,7 +1047,6 @@
c->cid.cid_dnid = ast_strdup(ext);
o->owner = c;
- ast_module_ref(ast_module_info->self);
ast_jb_configure(c, &global_jbconf);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(c)) {
@@ -1609,7 +1607,7 @@
return AST_MODULE_LOAD_FAILURE;
}
- if (ast_channel_register(&oss_tech)) {
+ if (ast_channel_register(&oss_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel type 'OSS'\n");
return AST_MODULE_LOAD_FAILURE;
}
Modified: team/file/usecnt-cleanup/channels/chan_phone.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_phone.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_phone.c (original)
+++ team/file/usecnt-cleanup/channels/chan_phone.c Mon Feb 12 18:10:24 2007
@@ -385,7 +385,6 @@
p->dialtone = 0;
memset(p->ext, 0, sizeof(p->ext));
((struct phone_pvt *)(ast->tech_pvt))->owner = NULL;
- 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;
@@ -908,7 +907,6 @@
tmp->cid.cid_name = ast_strdup(i->cid_name);
i->owner = tmp;
- ast_module_ref(ast_module_info->self);
if (state != AST_STATE_DOWN) {
if (state == AST_STATE_RING) {
ioctl(tmp->fds[0], PHONE_RINGBACK);
@@ -989,7 +987,6 @@
if (i->mode == MODE_IMMEDIATE) {
phone_new(i, AST_STATE_RING, i->context);
} else if (i->mode == MODE_DIALTONE) {
- ast_module_ref(ast_module_info->self);
/* Reset the extension */
i->ext[0] = '\0';
/* Play the dialtone */
@@ -999,7 +996,6 @@
ioctl(i->fd, PHONE_PLAY_START);
i->lastformat = -1;
} else if (i->mode == MODE_SIGMA) {
- ast_module_ref(ast_module_info->self);
/* Reset the extension */
i->ext[0] = '\0';
/* Play the dialtone */
@@ -1007,8 +1003,6 @@
ioctl(i->fd, PHONE_DIALTONE);
}
} else {
- if (i->dialtone)
- ast_module_unref(ast_module_info->self);
memset(i->ext, 0, sizeof(i->ext));
if (i->cpt)
{
@@ -1460,7 +1454,7 @@
/* Make sure we can register our Adtranphone channel type */
- if (ast_channel_register(cur_tech)) {
+ if (ast_channel_register(cur_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class 'Phone'\n");
ast_config_destroy(cfg);
__unload_module();
Modified: team/file/usecnt-cleanup/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_sip.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_sip.c (original)
+++ team/file/usecnt-cleanup/channels/chan_sip.c Mon Feb 12 18:10:24 2007
@@ -3562,7 +3562,6 @@
p->owner = NULL;
ast->tech_pvt = NULL;
- 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
If we get no answer during retransmit period, drop the call anyway.
@@ -4084,7 +4083,6 @@
if (!ast_strlen_zero(i->language))
ast_string_field_set(tmp, language, i->language);
i->owner = tmp;
- 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));
@@ -17626,7 +17624,7 @@
return AST_MODULE_LOAD_DECLINE;
/* Make sure we can register our sip channel type */
- if (ast_channel_register(&sip_tech)) {
+ if (ast_channel_register(&sip_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n");
io_context_destroy(io);
sched_context_destroy(sched);
Modified: team/file/usecnt-cleanup/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_skinny.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_skinny.c (original)
+++ team/file/usecnt-cleanup/channels/chan_skinny.c Mon Feb 12 18:10:24 2007
@@ -2753,7 +2753,6 @@
if (l->amaflags)
tmp->amaflags = l->amaflags;
- 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);
@@ -4613,7 +4612,7 @@
}
/* Make sure we can register our skinny channel type */
- if (ast_channel_register(&skinny_tech)) {
+ if (ast_channel_register(&skinny_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class 'Skinny'\n");
return -1;
}
Modified: team/file/usecnt-cleanup/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/channels/chan_zap.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/channels/chan_zap.c (original)
+++ team/file/usecnt-cleanup/channels/chan_zap.c Mon Feb 12 18:10:24 2007
@@ -2906,7 +2906,6 @@
p->oprmode = 0;
ast->tech_pvt = NULL;
ast_mutex_unlock(&p->lock);
- ast_module_unref(ast_module_info->self);
if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Hungup '%s'\n", ast->name);
@@ -5653,7 +5652,6 @@
}
}
- ast_module_ref(ast_module_info->self);
return tmp;
}
@@ -12624,7 +12622,7 @@
/* Make sure we can register our Zap channel type */
if (res)
return AST_MODULE_LOAD_DECLINE;
- if (ast_channel_register(&zap_tech)) {
+ if (ast_channel_register(&zap_tech, ast_module_info->self)) {
ast_log(LOG_ERROR, "Unable to register channel class 'Zap'\n");
__unload_module();
return -1;
Modified: team/file/usecnt-cleanup/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/channel.h?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/channel.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/channel.h Mon Feb 12 18:10:24 2007
@@ -695,12 +695,14 @@
struct ast_channel *__ast_request_and_dial(const char *type, int format, void *data, int timeout, int *reason, const char *cidnum, const char *cidname, struct outgoing_helper *oh);
+struct ast_module;
+
/*!\brief Register a channel technology (a new channel driver)
* Called by a channel module to register the kind of channels it supports.
* \param tech Structure defining channel technology or "type"
* \return Returns 0 on success, -1 on failure.
*/
-int ast_channel_register(const struct ast_channel_tech *tech);
+int ast_channel_register(const struct ast_channel_tech *tech, struct ast_module *mod);
/*! \brief Unregister a channel technology
* \param tech Structure defining channel technology or "type" that was previously registered
Modified: team/file/usecnt-cleanup/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/channel.c?view=diff&rev=54141&r1=54140&r2=54141
==============================================================================
--- team/file/usecnt-cleanup/main/channel.c (original)
+++ team/file/usecnt-cleanup/main/channel.c Mon Feb 12 18:10:24 2007
@@ -66,6 +66,7 @@
#include "asterisk/sha1.h"
#include "asterisk/threadstorage.h"
#include "asterisk/slinfactory.h"
+#include "asterisk/module.h"
struct channel_spy_trans {
int last_format;
@@ -105,6 +106,7 @@
#define AST_DEFAULT_EMULATE_DTMF_DURATION 100
struct chanlist {
+ struct ast_module *module;
const struct ast_channel_tech *tech;
AST_LIST_ENTRY(chanlist) list;
};
@@ -396,7 +398,7 @@
}
/*! \brief Register a new telephony channel in Asterisk */
-int ast_channel_register(const struct ast_channel_tech *tech)
+int ast_channel_register(const struct ast_channel_tech *tech, struct ast_module *mod)
{
struct chanlist *chan;
@@ -415,6 +417,7 @@
return -1;
}
chan->tech = tech;
+ chan->module = mod;
AST_LIST_INSERT_HEAD(&backends, chan, list);
if (option_debug)
@@ -1023,10 +1026,19 @@
struct varshead *headp;
struct ast_datastore *datastore = NULL;
char name[AST_CHANNEL_NAME];
+ struct chanlist *cl;
headp=&chan->varshead;
AST_LIST_LOCK(&channels);
+
+ AST_LIST_TRAVERSE(&backends, cl, list) {
+ if (cl->tech == chan->tech) {
+ ast_module_unref(cl->module);
+ break;
+ }
+ }
+
AST_LIST_REMOVE(&channels, chan, chan_list);
/* Lock and unlock the channel just to be sure nobody
has it locked still */
@@ -2919,11 +2931,18 @@
return NULL;
}
AST_LIST_UNLOCK(&channels);
- if (!chan->tech->requester)
+
+ ast_module_ref(chan->module);
+
+ if (!chan->tech->requester) {
+ ast_module_unref(chan->module);
return NULL;
+ }
- if (!(c = chan->tech->requester(type, capabilities | videoformat, data, cause)))
+ if (!(c = chan->tech->requester(type, capabilities | videoformat, data, cause))) {
+ ast_module_unref(chan->module);
return NULL;
+ }
/* no need to generate a Newchannel event here; it is done in the channel_alloc call */
return c;
More information about the asterisk-commits
mailing list