[asterisk-dev] [Code Review] Implement ast_channel_search_locked to expensive per-notify channel walk in chan_sip

Sean Bright sean.bright at gmail.com
Tue Nov 4 17:36:41 CST 2008


Brian Degenhardt wrote:
> Russell, at astridevcon we talked about CEL's method of seeing if a
> linkedid exists when a channel is destroyed, and how it needs to search
> all channels.  Would this be a reasonable substitute to accomplish that
> task?
> 
> Murf was going to do the whole hashtab thing, but this might be good enough.
> 
> What do you guys think?  Here's the current function, to refresh your
> memory:

You should be able to re-write it like this:

/* called whenever a channel is destroyed or a linkedid is changed to
potentially emit a CEL_LINKEDID_END event */
void ast_cel_check_retire_linkedid(const struct ast_channel *chan)
{
    auto int linkedid_match(struct ast_channel *c);
    int linkedid_match(struct ast_channel *c) {
        return (c != chan && c->linkedid && !strcmp(linkedid, c->linkedid));
    }
    const char *linkedid = chan->linkedid;

    /* make sure we need to do all this work */
    if (!ast_strlen_zero(linkedid) && track_event(CEL_LINKEDID_END)) {
	struct ast_channel *tmp = NULL;
        if ((tmp = ast_channel_search_locked(linkedid_match))) {
            ast_channel_unlock(tmp);
            tmp = NULL;
        } else {
            ast_cel_report_event(chan, CEL_LINKEDID_END, NULL, NULL, NULL);
        }
    }
}

And you're good to go.

-- 
Sean Bright
sean.bright at gmail.com



More information about the asterisk-dev mailing list