diff options
author | Sean Bright <sean@malleable.com> | 2008-11-04 23:23:39 +0000 |
---|---|---|
committer | Sean Bright <sean@malleable.com> | 2008-11-04 23:23:39 +0000 |
commit | 086a52d9d1cc00b28b3146376935b6c64b258cb0 (patch) | |
tree | cc80e865574edf9aedd9298a568c9b998b118374 /main | |
parent | bdb21bef93ce295c7593165a435fede4cf7034e4 (diff) |
Introduce a new API call ast_channel_search_locked, which iterates through the
channel list calling a caller-defined callback. The callback returns non-zero
if a match is found. This should speed up some of the code that I committed
earlier today in chan_sip (which is also updated by this commit).
Reviewed by russellb and kpfleming via ReviewBoard:
http://reviewboard.digium.com/r/28/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@154429 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r-- | main/channel.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/main/channel.c b/main/channel.c index 4174613ec..34733af54 100644 --- a/main/channel.c +++ b/main/channel.c @@ -1226,6 +1226,24 @@ struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *c return channel_find_locked(chan, NULL, 0, context, exten); } +/*! \brief Search for a channel based on the passed channel matching callback (first match) and return it, locked */ +struct ast_channel *ast_channel_search_locked(int (*is_match)(struct ast_channel *)) +{ + struct ast_channel *c = NULL; + + AST_RWLIST_RDLOCK(&channels); + AST_RWLIST_TRAVERSE(&channels, c, chan_list) { + ast_channel_lock(c); + if (is_match(c)) { + break; + } + ast_channel_unlock(c); + } + AST_RWLIST_UNLOCK(&channels); + + return c; +} + /*! \brief Wait, look for hangups and condition arg */ int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data) { |