[dahdi-commits] sruffell: linux/trunk r9383 - /linux/trunk/drivers/dahdi/dahdi-base.c

SVN commits to the DAHDI project dahdi-commits at lists.digium.com
Mon Sep 20 15:34:35 CDT 2010


Author: sruffell
Date: Mon Sep 20 15:34:32 2010
New Revision: 9383

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=9383
Log:
dahdi: Keep psuedo channels on pseudo_chan_list.

Since pseudo channels are without spans and we would like to use the
span list to enumerate through all the channels, keeping the psuedo
channels on their own list is required.  I believe this is a more
natural choice than making a dummy spans for pseudos since pseudo
channels should *really* just be an implementation detail that the user
shouldn't care about.

Review: https://reviewboard.asterisk.org/r/905/

Signed-off-by: Shaun Ruffell <sruffell at digium.com>

Modified:
    linux/trunk/drivers/dahdi/dahdi-base.c

Modified: linux/trunk/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/dahdi-base.c?view=diff&rev=9383&r1=9382&r2=9383
==============================================================================
--- linux/trunk/drivers/dahdi/dahdi-base.c (original)
+++ linux/trunk/drivers/dahdi/dahdi-base.c Mon Sep 20 15:34:32 2010
@@ -408,6 +408,19 @@
 static rwlock_t zone_lock = RW_LOCK_UNLOCKED;
 static rwlock_t chan_lock = RW_LOCK_UNLOCKED;
 #endif
+
+struct pseudo_chan {
+	struct dahdi_chan chan;
+	struct list_head node;
+};
+
+static inline struct pseudo_chan *chan_to_pseudo(struct dahdi_chan *chan)
+{
+	return container_of(chan, struct pseudo_chan, chan);
+}
+
+/* This is protected by the chan_lock. */
+static LIST_HEAD(pseudo_chans);
 
 /**
  * is_pseudo_chan() - By definition psuedo channels are not on a span.
@@ -2867,7 +2880,8 @@
 
 static struct dahdi_chan *dahdi_alloc_pseudo(void)
 {
-	struct dahdi_chan *pseudo;
+	struct pseudo_chan *pseudo;
+	unsigned long flags;
 
 	/* Don't allow /dev/dahdi/pseudo to open if there is not a timing
 	 * source. */
@@ -2877,27 +2891,44 @@
 	if (!(pseudo = kzalloc(sizeof(*pseudo), GFP_KERNEL)))
 		return NULL;
 
-	pseudo->sig = DAHDI_SIG_CLEAR;
-	pseudo->sigcap = DAHDI_SIG_CLEAR;
-	pseudo->flags = DAHDI_FLAG_AUDIO;
-	pseudo->span = NULL; /* No span == psuedo channel */
-
-	if (dahdi_chan_reg(pseudo)) {
+	INIT_LIST_HEAD(&pseudo->node);
+
+	pseudo->chan.sig = DAHDI_SIG_CLEAR;
+	pseudo->chan.sigcap = DAHDI_SIG_CLEAR;
+	pseudo->chan.flags = DAHDI_FLAG_AUDIO;
+	pseudo->chan.span = NULL; /* No span == psuedo channel */
+
+	if (dahdi_chan_reg(&pseudo->chan)) {
 		kfree(pseudo);
-		pseudo = NULL;
-	} else {
-		snprintf(pseudo->name, sizeof(pseudo->name)-1,"Pseudo/%d", pseudo->channo); 
-	}
-
-	return pseudo;
-}
-
-static void dahdi_free_pseudo(struct dahdi_chan *pseudo)
-{
-	if (pseudo) {
-		dahdi_chan_unreg(pseudo);
-		kfree(pseudo);
-	}
+		return NULL;
+	}
+
+	write_lock_irqsave(&chan_lock, flags);
+	list_add_tail(&pseudo->node, &pseudo_chans);
+	write_unlock_irqrestore(&chan_lock, flags);
+
+	snprintf(pseudo->chan.name, sizeof(pseudo->chan.name)-1,
+		 "Pseudo/%d", pseudo->chan.channo);
+
+	return &pseudo->chan;
+}
+
+static void dahdi_free_pseudo(struct dahdi_chan *chan)
+{
+	struct pseudo_chan *pseudo;
+	unsigned long flags;
+
+	if (!chan)
+		return;
+
+	pseudo = chan_to_pseudo(chan);
+
+	write_lock_irqsave(&chan_lock, flags);
+	list_del(&pseudo->node);
+	write_unlock_irqrestore(&chan_lock, flags);
+
+	dahdi_chan_unreg(chan);
+	kfree(pseudo);
 }
 
 static int dahdi_open(struct inode *inode, struct file *file)




More information about the dahdi-commits mailing list