aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-04-24 14:04:26 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-04-24 14:04:26 +0000
commit89175b7e049f8203ece12ba74301d7ad9385c050 (patch)
tree1812569845aaf29df5f2a18285e73bc1fcc6268c /channels
parenta8182a597e392aa831f2e6960a71d3554fc34aa9 (diff)
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big improvement for performance, stability, code maintainability, and ease of future code development. The channel list is no longer an unsorted linked list. The main container for channels is an astobj2 hash table. All of the code related to searching for channels or iterating active channels has been rewritten. Let n be the number of active channels. Iterating the channel list has gone from O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1). Searching for a channel by extension is still O(n), but uses a new method for doing so, which is more efficient. The ast_channel object is now a reference counted object. The benefits here are plentiful. Some benefits directly related to issues in the previous code include: 1) When threads other than the channel thread owning a channel wanted access to a channel, it had to hold the lock on it to ensure that it didn't go away. This is no longer a requirement. Holding a reference is sufficient. 2) There are places that now require less dealing with channel locks. 3) There are places where channel locks are held for much shorter periods of time. 4) There are places where dealing with more than one channel at a time becomes _MUCH_ easier. ChanSpy is a great example of this. Writing code in the future that deals with multiple channels will be much easier. Some additional information regarding channel locking and reference count handling can be found in channel.h, where a new section has been added that discusses some of the rules associated with it. Mark Michelson also assisted with the development of this patch. He did the conversion of ChanSpy and introduced a new API, ast_autochan, which makes it much easier to deal with holding on to a channel pointer for an extended period of time and having it get automatically updated if the channel gets masqueraded. Mark was also a huge help in the code review process. Thanks to David Vossel for his assistance with this branch, as well. David did the conversion of the DAHDIScan application by making it become a wrapper for ChanSpy internally. The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch. Review: http://reviewboard.digium.com/r/203/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_agent.c9
-rw-r--r--channels/chan_bridge.c2
-rw-r--r--channels/chan_dahdi.c10
-rw-r--r--channels/chan_gtalk.c2
-rw-r--r--channels/chan_iax2.c2
-rw-r--r--channels/chan_local.c9
-rw-r--r--channels/chan_mgcp.c1
-rw-r--r--channels/chan_misdn.c2
-rw-r--r--channels/chan_sip.c20
-rw-r--r--channels/chan_unistim.c6
10 files changed, 38 insertions, 25 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c
index 535056ecb..b705b6f04 100644
--- a/channels/chan_agent.c
+++ b/channels/chan_agent.c
@@ -463,8 +463,9 @@ static int agent_cleanup(struct agent_pvt *p)
/* Release ownership of the agent to other threads (presumably running the login app). */
p->app_lock_flag = 0;
ast_cond_signal(&p->app_complete_cond);
- if (chan)
- ast_channel_free(chan);
+ if (chan) {
+ chan = ast_channel_release(chan);
+ }
if (p->dead) {
ast_mutex_destroy(&p->lock);
ast_mutex_destroy(&p->app_lock);
@@ -1124,7 +1125,7 @@ static struct ast_channel *agent_new(struct agent_pvt *p, int state)
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. */
p->app_lock_flag = 0;
ast_cond_signal(&p->app_complete_cond);
@@ -1138,7 +1139,7 @@ static struct ast_channel *agent_new(struct agent_pvt *p, int state)
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;
}
diff --git a/channels/chan_bridge.c b/channels/chan_bridge.c
index bd1d0fbee..be41cd86c 100644
--- a/channels/chan_bridge.c
+++ b/channels/chan_bridge.c
@@ -204,7 +204,7 @@ static struct ast_channel *bridge_request(const char *type, int format, void *da
return NULL;
}
if (!(p->output = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", 0, "Bridge/%p-output", p))) {
- ast_channel_free(p->input);
+ p->input = ast_channel_release(p->input);
ast_free(p);
return NULL;
}
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index d2f7f727c..44b854a77 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -12075,9 +12075,13 @@ static int pri_fixup_principle(struct dahdi_pri *pri, int principle, q931_call *
new->owner = old->owner;
old->owner = NULL;
if (new->owner) {
- ast_string_field_build(new->owner, name,
- "DAHDI/%d:%d-%d", pri->trunkgroup,
- new->channel, 1);
+ char newname[AST_CHANNEL_NAME];
+
+ snprintf(newname, sizeof(newname),
+ "DAHDI/%d:%d-%d", pri->trunkgroup, new->channel, 1);
+
+ ast_change_name(new->owner, newname);
+
new->owner->tech_pvt = new;
ast_channel_set_fd(new->owner, 0, new->subs[SUB_REAL].dfd);
new->subs[SUB_REAL].owner = old->subs[SUB_REAL].owner;
diff --git a/channels/chan_gtalk.c b/channels/chan_gtalk.c
index 417817eb8..7b430fa09 100644
--- a/channels/chan_gtalk.c
+++ b/channels/chan_gtalk.c
@@ -1223,7 +1223,7 @@ static int gtalk_newcall(struct gtalk *client, ikspak *pak)
gtalk_action(client, p, "reject");
p->alreadygone = 1;
gtalk_hangup(chan);
- ast_channel_free(chan);
+ ast_channel_release(chan);
return -1;
}
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index e07858fe1..a55f75aae 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -4483,7 +4483,7 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
if (tmp) {
/* unlock and relock iaxsl[callno] to preserve locking order */
ast_mutex_unlock(&iaxsl[callno]);
- ast_channel_free(tmp);
+ tmp = ast_channel_release(tmp);
ast_mutex_lock(&iaxsl[callno]);
}
return NULL;
diff --git a/channels/chan_local.c b/channels/chan_local.c
index 5518a7155..7e7ef3c4e 100644
--- a/channels/chan_local.c
+++ b/channels/chan_local.c
@@ -793,13 +793,12 @@ static struct ast_channel *local_new(struct local_pvt *p, int state)
ama = 0;
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);
- if (tmp2)
- ast_channel_free(tmp2);
+ if (tmp) {
+ tmp = ast_channel_release(tmp);
+ }
ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
return NULL;
- }
+ }
tmp2->tech = tmp->tech = &local_tech;
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index 80b939393..0ba8290a1 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -1479,7 +1479,6 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state)
if (!tmp->nativeformats)
tmp->nativeformats = capability;
fmt = ast_best_codec(tmp->nativeformats);
- ast_string_field_build(tmp, name, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id);
if (sub->rtp)
ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
if (i->dtmfmode & (MGCP_DTMF_INBAND | MGCP_DTMF_HYBRID)) {
diff --git a/channels/chan_misdn.c b/channels/chan_misdn.c
index c246b9b93..132f0d1d2 100644
--- a/channels/chan_misdn.c
+++ b/channels/chan_misdn.c
@@ -7738,7 +7738,9 @@ static void update_name(struct ast_channel *tmp, int port, int c)
snprintf(newname, sizeof(newname), "%s/%d-", misdn_type, chan_offset + c);
if (strncmp(tmp->name, newname, strlen(newname))) {
snprintf(newname, sizeof(newname), "%s/%d-u%d", misdn_type, chan_offset + c, glob_channel++);
+ ast_channel_lock(tmp);
ast_change_name(tmp, newname);
+ ast_channel_unlock(tmp);
chan_misdn_log(3, port, " --> updating channel name to [%s]\n", tmp->name);
}
}
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 292d4cd4c..c20ca70f5 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -10347,12 +10347,21 @@ static int __sip_subscribe_mwi_do(struct sip_subscription_mwi *mwi)
return 0;
}
-static int find_calling_channel(struct ast_channel *c, void *data) {
+static int find_calling_channel(void *obj, void *arg, void *data, int flags)
+{
+ struct ast_channel *c = obj;
struct sip_pvt *p = data;
+ int res;
+
+ ast_channel_lock(c);
- return (c->pbx &&
+ res = (c->pbx &&
(!strcasecmp(c->macroexten, p->exten) || !strcasecmp(c->exten, p->exten)) &&
(sip_cfg.notifycid == IGNORE_CONTEXT || !strcasecmp(c->context, p->context)));
+
+ ast_channel_unlock(c);
+
+ return res ? CMP_MATCH | CMP_STOP : 0;
}
/*! \brief Builds XML portion of state NOTIFY messages */
@@ -10471,15 +10480,16 @@ static void state_notify_build_xml(int state, int full, const char *exten, const
callee must be dialing the same extension that is being monitored. Simply dialing
the hint'd device is not sufficient. */
if (sip_cfg.notifycid) {
- struct ast_channel *caller = ast_channel_search_locked(find_calling_channel, p);
+ struct ast_channel *caller;
- if (caller) {
+ if ((caller = ast_channel_callback(find_calling_channel, NULL, p, 0))) {
int need = strlen(caller->cid.cid_num) + strlen(p->fromdomain) + sizeof("sip:@");
local_target = alloca(need);
+ ast_channel_lock(caller);
snprintf(local_target, need, "sip:%s@%s", caller->cid.cid_num, p->fromdomain);
local_display = ast_strdupa(caller->cid.cid_name);
ast_channel_unlock(caller);
- caller = NULL;
+ caller = ast_channel_unref(caller);
}
}
diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index 127bfed45..4706daa00 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -4433,8 +4433,8 @@ static struct ast_channel *unistim_new(struct unistim_subchannel *sub, int state
return NULL;
}
l = sub->parent;
- tmp = ast_channel_alloc(1, state, l->cid_num, NULL, l->accountcode, l->exten,
- l->context, l->amaflags, "%s-%08x", l->fullname, (int) (long) sub);
+ tmp = ast_channel_alloc(1, state, l->cid_num, NULL, l->accountcode, l->exten,
+ l->context, l->amaflags, "%s@%s-%d", l->name, l->parent->name, sub->subtype);
if (unistimdebug)
ast_verb(0, "unistim_new sub=%d (%p) chan=%p\n", sub->subtype, sub, tmp);
if (!tmp) {
@@ -4449,8 +4449,6 @@ static struct ast_channel *unistim_new(struct unistim_subchannel *sub, int state
if (unistimdebug)
ast_verb(0, "Best codec = %d from nativeformats %d (line cap=%d global=%d)\n", fmt,
tmp->nativeformats, l->capability, CAPABILITY);
- ast_string_field_build(tmp, name, "USTM/%s@%s-%d", l->name, l->parent->name,
- sub->subtype);
if ((sub->rtp) && (sub->subtype == 0)) {
if (unistimdebug)
ast_verb(0, "New unistim channel with a previous rtp handle ?\n");