[asterisk-commits] russell: branch russell/chan_refcount r82625 - in /team/russell/chan_refcount...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Sep 17 12:33:22 CDT 2007
Author: russell
Date: Mon Sep 17 12:33:22 2007
New Revision: 82625
URL: http://svn.digium.com/view/asterisk?view=rev&rev=82625
Log:
Rename ast_channel_free to ast_channel_release since it doesn't free a channel.
It unlinks it from the channels container if it is still there and releases a
reference. Also, fix some channel locking bugs along the way ...
Modified:
team/russell/chan_refcount/apps/app_minivm.c
team/russell/chan_refcount/apps/app_voicemail.c
team/russell/chan_refcount/channels/chan_agent.c
team/russell/chan_refcount/channels/chan_local.c
team/russell/chan_refcount/include/asterisk/cdr.h
team/russell/chan_refcount/include/asterisk/channel.h
team/russell/chan_refcount/main/channel.c
team/russell/chan_refcount/main/logger.c
team/russell/chan_refcount/main/pbx.c
team/russell/chan_refcount/res/res_features.c
Modified: team/russell/chan_refcount/apps/app_minivm.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/apps/app_minivm.c?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/apps/app_minivm.c (original)
+++ team/russell/chan_refcount/apps/app_minivm.c Mon Sep 17 12:33:22 2007
@@ -744,6 +744,8 @@
return;
}
+ ast_channel_lock(channel);
+
for (var = vmu->chanvars ; var ; var = var->next)
pbx_builtin_setvar_helper(channel, var->name, var->value);
@@ -758,6 +760,8 @@
pbx_builtin_setvar_helper(channel, "MVM_DATE", date);
if (!ast_strlen_zero(counter))
pbx_builtin_setvar_helper(channel, "MVM_COUNTER", counter);
+
+ ast_channel_unlock(channel);
}
/*! \brief Set default values for Mini-Voicemail users */
@@ -1052,7 +1056,9 @@
int vmlen = strlen(template->subject) * 3 + 200;
if ((passdata = alloca(vmlen))) {
memset(passdata, 0, vmlen);
+ ast_channel_lock(ast);
pbx_substitute_variables_helper(ast, template->subject, passdata, vmlen);
+ ast_channel_unlock(ast);
fprintf(p, "Subject: %s\n", passdata);
} else {
ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
@@ -1119,7 +1125,7 @@
ast_debug(1, "Sent message to %s with command '%s' - %s\n", vmu->email, global_mailcmd, template->attachment ? "(media attachment)" : "");
ast_debug(3, "-_-_- Actual command used: %s\n", tmp2);
if (ast)
- ast_channel_free(ast);
+ ast = ast_channel_release(ast);
return 0;
}
Modified: team/russell/chan_refcount/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/apps/app_voicemail.c?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/apps/app_voicemail.c (original)
+++ team/russell/chan_refcount/apps/app_voicemail.c Mon Sep 17 12:33:22 2007
@@ -1979,16 +1979,16 @@
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
char *passdata;
int vmlen = strlen(fromstring)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
- pbx_substitute_variables_helper(ast, fromstring, passdata, vmlen);
- len_passdata = strlen(passdata) * 2 + 3;
- passdata2 = alloca(len_passdata);
- fprintf(p, "From: %s <%s>" ENDL, quote(passdata, passdata2, len_passdata), who);
- } else
- ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
+ passdata = alloca(vmlen);
+ memset(passdata, 0, vmlen);
+ ast_channel_lock(ast);
+ prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+ pbx_substitute_variables_helper(ast, fromstring, passdata, vmlen);
+ ast_channel_unlock(ast);
+ len_passdata = strlen(passdata) * 2 + 3;
+ passdata2 = alloca(len_passdata);
+ fprintf(p, "From: %s <%s>" ENDL, quote(passdata, passdata2, len_passdata), who);
+ ast = ast_channel_release(ast);
} else
ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
} else
@@ -2001,14 +2001,14 @@
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
char *passdata;
int vmlen = strlen(emailsubject) * 3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
- pbx_substitute_variables_helper(ast, emailsubject, passdata, vmlen);
- fprintf(p, "Subject: %s" ENDL, passdata);
- } else
- ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
+ passdata = alloca(vmlen);
+ memset(passdata, 0, vmlen);
+ ast_channel_lock(ast);
+ prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+ pbx_substitute_variables_helper(ast, emailsubject, passdata, vmlen);
+ ast_channel_unlock(ast);
+ fprintf(p, "Subject: %s" ENDL, passdata);
+ ast = ast_channel_release(ast);
} else
ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
} else if (!ast_strlen_zero(emailtitle)) {
@@ -2056,14 +2056,14 @@
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
char *passdata;
int vmlen = strlen(emailbody)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
- pbx_substitute_variables_helper(ast, emailbody, passdata, vmlen);
- fprintf(p, "%s" ENDL, passdata);
- } else
- ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
+ passdata = alloca(vmlen);
+ memset(passdata, 0, vmlen);
+ ast_channel_lock(ast);
+ prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+ pbx_substitute_variables_helper(ast, emailbody, passdata, vmlen);
+ ast_channel_unlock(ast);
+ fprintf(p, "%s" ENDL, passdata);
+ ast = ast_channel_release(ast);
} else
ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
} else if (msgnum > -1){
@@ -2175,14 +2175,14 @@
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
char *passdata;
int vmlen = strlen(fromstring)*3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
- pbx_substitute_variables_helper(ast, pagerfromstring, passdata, vmlen);
- fprintf(p, "From: %s <%s>\n", passdata, who);
- } else
- ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
+ passdata = alloca(vmlen);
+ memset(passdata, 0, vmlen);
+ ast_channel_lock(ast);
+ prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+ pbx_substitute_variables_helper(ast, pagerfromstring, passdata, vmlen);
+ ast_channel_unlock(ast);
+ fprintf(p, "From: %s <%s>\n", passdata, who);
+ ast = ast_channel_release(ast);
} else
ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
} else
@@ -2193,14 +2193,14 @@
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
char *passdata;
int vmlen = strlen(pagersubject) * 3 + 200;
- if ((passdata = alloca(vmlen))) {
- memset(passdata, 0, vmlen);
- prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
- pbx_substitute_variables_helper(ast, pagersubject, passdata, vmlen);
- fprintf(p, "Subject: %s\n\n", passdata);
- } else
- ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n");
- ast_channel_free(ast);
+ passdata = alloca(vmlen);
+ memset(passdata, 0, vmlen);
+ ast_channel_lock(ast);
+ prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
+ pbx_substitute_variables_helper(ast, pagersubject, passdata, vmlen);
+ ast_channel_unlock(ast);
+ fprintf(p, "Subject: %s\n\n", passdata);
+ ast = ast_channel_release(ast);
} else
ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
} else
@@ -2214,10 +2214,12 @@
int vmlen = strlen(pagerbody) * 3 + 200;
passdata = alloca(vmlen);
memset(passdata, 0, vmlen);
+ ast_channel_lock(ast);
prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category);
pbx_substitute_variables_helper(ast, pagerbody, passdata, vmlen);
+ ast_channel_unlock(ast);
fprintf(p, "%s\n", passdata);
- ast_channel_free(ast);
+ ast = ast_channel_release(ast);
} else
ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
} else {
Modified: team/russell/chan_refcount/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/channels/chan_agent.c?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/channels/chan_agent.c (original)
+++ team/russell/chan_refcount/channels/chan_agent.c Mon Sep 17 12:33:22 2007
@@ -355,18 +355,23 @@
static int agent_cleanup(struct agent_pvt *p)
{
struct ast_channel *chan = p->owner;
+
p->owner = NULL;
chan->tech_pvt = NULL;
p->app_sleep_cond = 1;
+
/* Release ownership of the agent to other threads (presumably running the login app). */
ast_mutex_unlock(&p->app_lock);
+
if (chan)
- ast_channel_free(chan);
+ ast_channel_release(chan);
+
if (p->dead) {
ast_mutex_destroy(&p->lock);
ast_mutex_destroy(&p->app_lock);
ast_free(p);
- }
+ }
+
return 0;
}
@@ -945,7 +950,7 @@
p->owner = NULL;
tmp->tech_pvt = NULL;
p->app_sleep_cond = 1;
- ast_channel_free( tmp );
+ tmp = ast_channel_release(tmp);
ast_mutex_unlock(&p->lock); /* For other thread to read the condition. */
ast_mutex_unlock(&p->app_lock);
return NULL;
@@ -958,7 +963,7 @@
p->owner = NULL;
tmp->tech_pvt = NULL;
p->app_sleep_cond = 1;
- ast_channel_free( tmp );
+ tmp = ast_channel_release(tmp);
ast_mutex_unlock(&p->lock); /* For other thread to read the condition. */
return NULL;
}
Modified: team/russell/chan_refcount/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/channels/chan_local.c?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/channels/chan_local.c (original)
+++ team/russell/chan_refcount/channels/chan_local.c Mon Sep 17 12:33:22 2007
@@ -615,9 +615,9 @@
if (!(tmp = ast_channel_alloc(1, state, 0, 0, t, p->exten, p->context, ama, "Local/%s@%s-%04x;1", p->exten, p->context, randnum))
|| !(tmp2 = ast_channel_alloc(1, AST_STATE_RING, 0, 0, t, p->exten, p->context, ama, "Local/%s@%s-%04x;2", p->exten, p->context, randnum))) {
if (tmp)
- ast_channel_free(tmp);
+ tmp = ast_channel_release(tmp);
if (tmp2)
- ast_channel_free(tmp2);
+ tmp2 = ast_channel_release(tmp2);
ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
return NULL;
}
Modified: team/russell/chan_refcount/include/asterisk/cdr.h
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/include/asterisk/cdr.h?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/include/asterisk/cdr.h (original)
+++ team/russell/chan_refcount/include/asterisk/cdr.h Mon Sep 17 12:33:22 2007
@@ -136,10 +136,15 @@
/*!
* \brief Initialize based on a channel
+ *
* \param cdr Call Detail Record to use for channel
* \param chan Channel to bind CDR with
+ *
* Initializes a CDR and associates it with a particular channel
+ *
* \return 0 by default
+ *
+ * \note The channel should be locked before calling this function.
*/
int ast_cdr_init(struct ast_cdr *cdr, struct ast_channel *chan);
@@ -172,9 +177,15 @@
/*!
* \brief Start a call
- * \param cdr the cdr you wish to associate with the call
+ *
+ * \param cdr the cdr you wish to associate with the call
+ *
* Starts all CDR stuff necessary for monitoring a call
- * Returns nothing
+ *
+ * \return nothing
+ *
+ * \note If this cdr lives on a channel, the channel should be locked before
+ * calling this function.
*/
void ast_cdr_start(struct ast_cdr *cdr);
@@ -201,8 +212,13 @@
/*!
* \brief Fail a call
- * \param cdr the cdr you wish to associate with the call
- * Returns nothing
+ *
+ * \param cdr the cdr you wish to associate with the call
+ *
+ * \return nothing
+ *
+ * \note If this cdr lives on a channel, the channel should be locked before
+ * calling this function.
*/
void ast_cdr_failed(struct ast_cdr *cdr);
@@ -216,18 +232,30 @@
/*!
* \brief End a call
+ *
* \param cdr the cdr you have associated the call with
+ *
* Registers the end of call time in the cdr structure.
- * Returns nothing
+ *
+ * \return nothing
+ *
+ * \note If this cdr lives on a channel, the channel should be locked before
+ * calling this function.
*/
void ast_cdr_end(struct ast_cdr *cdr);
/*!
* \brief Detaches the detail record for posting (and freeing) either now or at a
- * later time in bulk with other records during batch mode operation.
+ * later time in bulk with other records during batch mode operation.
+ *
* \param cdr Which CDR to detach from the channel thread
+ *
* Prevents the channel thread from blocking on the CDR handling
- * Returns nothing
+ *
+ * \return nothing
+ *
+ * \note If this cdr lives on a channel, the channel should be locked before
+ * calling this function.
*/
void ast_cdr_detach(struct ast_cdr *cdr);
@@ -241,10 +269,15 @@
/*!
* \brief Set the destination channel, if there was one
+ *
* \param cdr Which cdr it's applied to
* \param chan Channel to which dest will be
+ *
* Sets the destination channel the CDR is applied to
- * Returns nothing
+ *
+ * \return nothing
+ *
+ * \note The channel should be locked before calling this function.
*/
void ast_cdr_setdestchan(struct ast_cdr *cdr, const char *chan);
Modified: team/russell/chan_refcount/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/include/asterisk/channel.h?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/include/asterisk/channel.h (original)
+++ team/russell/chan_refcount/include/asterisk/channel.h Mon Sep 17 12:33:22 2007
@@ -748,7 +748,7 @@
*
* \return NULL, convenient for clearing invalid pointers
*/
-struct ast_channel *ast_channel_free(struct ast_channel *);
+struct ast_channel *ast_channel_release(struct ast_channel *);
/*!
* \brief Requests a channel
Modified: team/russell/chan_refcount/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/main/channel.c?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/main/channel.c (original)
+++ team/russell/chan_refcount/main/channel.c Mon Sep 17 12:33:22 2007
@@ -629,7 +629,7 @@
cid->cid_dnid = cid->cid_num = cid->cid_name = cid->cid_ani = cid->cid_rdnis = NULL;
}
-struct ast_channel *ast_channel_free(struct ast_channel *chan)
+struct ast_channel *ast_channel_release(struct ast_channel *chan)
{
/* Safe, even if already unlinked. */
ao2_unlink(channels, chan);
@@ -1438,7 +1438,6 @@
ast_debug(1, "Hanging up zombie '%s'\n", chan->name);
}
- ast_channel_unlock(chan);
manager_event(EVENT_FLAG_CALL, "Hangup",
"Channel: %s\r\n"
"Uniqueid: %s\r\n"
@@ -1449,7 +1448,10 @@
chan->hangupcause,
ast_cause2str(chan->hangupcause)
);
- chan = ast_channel_free(chan);
+
+ ast_channel_unlock(chan);
+
+ chan = ast_channel_release(chan);
if (cdr)
ast_cdr_detach(cdr);
@@ -3655,7 +3657,6 @@
zombie, then free it now (since it already is considered invalid). */
if (ast_test_flag(clone, AST_FLAG_ZOMBIE)) {
ast_debug(1, "Destroying channel clone '%s'\n", clone->name);
- ast_channel_unlock(clone);
manager_event(EVENT_FLAG_CALL, "Hangup",
"Channel: %s\r\n"
"Uniqueid: %s\r\n"
@@ -3666,7 +3667,8 @@
clone->hangupcause,
ast_cause2str(clone->hangupcause)
);
- clone = ast_channel_free(clone);
+ ast_channel_unlock(clone);
+ clone = ast_channel_release(clone);
} else {
ast_debug(1, "Released clone lock on '%s'\n", clone->name);
ast_set_flag(clone, AST_FLAG_ZOMBIE);
Modified: team/russell/chan_refcount/main/logger.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/main/logger.c?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/main/logger.c (original)
+++ team/russell/chan_refcount/main/logger.c Mon Sep 17 12:33:22 2007
@@ -506,10 +506,12 @@
if (!ast_strlen_zero(exec_after_rotate)) {
struct ast_channel *c = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Logger/rotate");
char buf[512] = "";
+ ast_channel_lock(c);
pbx_builtin_setvar_helper(c, "filename", filename);
pbx_substitute_variables_helper(c, exec_after_rotate, buf, sizeof(buf));
+ ast_channel_unlock(c);
system(buf);
- ast_channel_free(c);
+ c = ast_channel_release(c);
}
return res;
}
Modified: team/russell/chan_refcount/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/main/pbx.c?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/main/pbx.c (original)
+++ team/russell/chan_refcount/main/pbx.c Mon Sep 17 12:33:22 2007
@@ -1594,12 +1594,16 @@
struct varshead old;
struct ast_channel *c = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/%p", vars);
if (c) {
+ ast_channel_lock(c);
memcpy(&old, &c->varshead, sizeof(old));
memcpy(&c->varshead, headp, sizeof(c->varshead));
+ ast_channel_unlock(c);
cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
/* Don't deallocate the varshead that was passed in */
+ ast_channel_lock(c);
memcpy(&c->varshead, &old, sizeof(c->varshead));
- ast_channel_free(c);
+ ast_channel_unlock(c);
+ c = ast_channel_release(c);
} else
ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n");
}
@@ -4959,17 +4963,20 @@
if (!chan->cdr) {
/* allocation of the cdr failed */
- ast_channel_free(chan); /* free the channel */
+ ast_channel_release(chan); /* free the channel */
return -1; /* return failure */
}
/* allocation of the cdr was successful */
+ ast_channel_lock(chan);
ast_cdr_init(chan->cdr, chan); /* initialize our channel's cdr */
ast_cdr_start(chan->cdr); /* record the start and stop time */
ast_cdr_end(chan->cdr);
ast_cdr_failed(chan->cdr); /* set the status to failed */
ast_cdr_detach(chan->cdr); /* post and free the record */
- ast_channel_free(chan); /* free the channel */
+ ast_channel_unlock(chan);
+
+ ast_channel_release(chan); /* free the channel */
return 0; /* success */
}
Modified: team/russell/chan_refcount/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/res/res_features.c?view=diff&rev=82625&r1=82624&r2=82625
==============================================================================
--- team/russell/chan_refcount/res/res_features.c (original)
+++ team/russell/chan_refcount/res/res_features.c Mon Sep 17 12:33:22 2007
@@ -2502,7 +2502,7 @@
if (!(tmpchanb = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL,
NULL, NULL, 0, "Bridge/%s", chanb->name))) {
err_msg = "Unable to create temporary channel!";
- ast_channel_free(tmpchana);
+ tmpchana = ast_channel_release(tmpchana);
res = 1;
goto return_cleanup;
}
More information about the asterisk-commits
mailing list