[svn-commits] sruffell: branch linux/sruffell/chan_list r9344 - /linux/team/sruffell/chan_l...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Sep 17 14:11:52 CDT 2010


Author: sruffell
Date: Fri Sep 17 14:11:41 2010
New Revision: 9344

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=9344
Log:
dahdi: Drop 'chans' reference in chan_from_num.

Part of getting rid of global chans array.  We need to search the list
of spans and the list of pseudo channels.  While this is slower than a
direct index into a 'chans' array, the places where this function is
called are not in the 'hot' path but instead part of channel
configuration and conferencing setup.

Modified:
    linux/team/sruffell/chan_list/drivers/dahdi/dahdi-base.c

Modified: linux/team/sruffell/chan_list/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/sruffell/chan_list/drivers/dahdi/dahdi-base.c?view=diff&rev=9344&r1=9343&r2=9344
==============================================================================
--- linux/team/sruffell/chan_list/drivers/dahdi/dahdi-base.c (original)
+++ linux/team/sruffell/chan_list/drivers/dahdi/dahdi-base.c Fri Sep 17 14:11:41 2010
@@ -441,9 +441,41 @@
 
 static struct dahdi_chan *chans[DAHDI_MAX_CHANNELS];
 
-static inline struct dahdi_chan *chan_from_num(unsigned int channo)
-{
-	return valid_channo(channo) ? chans[channo] : NULL;
+static struct dahdi_chan *chan_from_num(unsigned int channo)
+{
+	struct dahdi_span *s;
+	struct pseudo_chan *pseudo;
+
+	if (!unlikely(valid_channo(channo)))
+		return NULL;
+
+	/* When searching for the channel amongst the spans, we can use the
+	 * fact that channels on a span must be numbered consecutively to skip
+	 * checking each individual channel. */
+	list_for_each_entry(s, &span_list, node) {
+		unsigned int basechan;
+		struct dahdi_chan *chan;
+
+		if (unlikely(!s->channels))
+			continue;
+
+		basechan = s->chans[0]->channo;
+		if (channo >= (basechan + s->channels))
+			continue;
+
+		chan = s->chans[channo - basechan];
+		WARN_ON(chan->channo != channo);
+		return chan;
+	}
+
+	/* If we didn't find the channel on the list of real channels, then
+	 * it's most likely a pseudo channel. */
+	list_for_each_entry(pseudo, &pseudo_chans, node) {
+		if (pseudo->chan.channo == channo)
+			return &pseudo->chan;
+	}
+
+	return NULL;
 }
 
 static inline struct dahdi_chan *chan_from_file(struct file *file)




More information about the svn-commits mailing list