From 086a52d9d1cc00b28b3146376935b6c64b258cb0 Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Tue, 4 Nov 2008 23:23:39 +0000 Subject: 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 --- main/channel.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'main') 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) { -- cgit v1.2.3