[zaptel-commits] kpfleming: branch mogorman/zaptel-1.2-transcoder r2047 - /team/mogorman/zapte...

zaptel-commits at lists.digium.com zaptel-commits at lists.digium.com
Wed Jan 31 08:51:34 MST 2007


Author: kpfleming
Date: Wed Jan 31 09:51:33 2007
New Revision: 2047

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2047
Log:
use kernel list macros for transcoder list instead of rolling our own

Modified:
    team/mogorman/zaptel-1.2-transcoder/zaptel.h
    team/mogorman/zaptel-1.2-transcoder/zttranscode.c

Modified: team/mogorman/zaptel-1.2-transcoder/zaptel.h
URL: http://svn.digium.com/view/zaptel/team/mogorman/zaptel-1.2-transcoder/zaptel.h?view=diff&rev=2047&r1=2046&r2=2047
==============================================================================
--- team/mogorman/zaptel-1.2-transcoder/zaptel.h (original)
+++ team/mogorman/zaptel-1.2-transcoder/zaptel.h Wed Jan 31 09:51:33 2007
@@ -45,6 +45,7 @@
 #include <linux/interrupt.h>
 #endif
 #include <linux/fs.h>
+#include <linux/list.h>
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 #define LINUX26
@@ -1419,7 +1420,7 @@
 #define ZT_TC_FLAG_TRANSIENT  (1 << 1)
 
 struct zt_transcoder {
-	struct zt_transcoder *next;
+	struct list_head list;
 	char name[80];
 	int numchannels;
 	unsigned int srcfmts;

Modified: team/mogorman/zaptel-1.2-transcoder/zttranscode.c
URL: http://svn.digium.com/view/zaptel/team/mogorman/zaptel-1.2-transcoder/zttranscode.c?view=diff&rev=2047&r1=2046&r2=2047
==============================================================================
--- team/mogorman/zaptel-1.2-transcoder/zttranscode.c (original)
+++ team/mogorman/zaptel-1.2-transcoder/zttranscode.c Wed Jan 31 09:51:33 2007
@@ -48,7 +48,7 @@
 #endif
 
 static int debug = 0;
-static struct zt_transcoder *trans;
+static LIST_HEAD(trans);
 static spinlock_t translock = SPIN_LOCK_UNLOCKED;
 
 EXPORT_SYMBOL(zt_transcoder_register);
@@ -69,6 +69,7 @@
 	memset(ztc, 0, size);
 	strcpy(ztc->name, "<unspecified>");
 	ztc->numchannels = numchans;
+	INIT_LIST_HEAD(&ztc->list);
 	for (x=0;x<ztc->numchannels;x++) {
 		init_waitqueue_head(&ztc->channels[x].ready);
 		ztc->channels[x].parent = ztc;
@@ -108,54 +109,46 @@
 int zt_transcoder_register(struct zt_transcoder *tc)
 {
 	struct zt_transcoder *cur;
-	int res = -EBUSY;
 
 	spin_lock(&translock);
-	for (cur = trans; cur; cur = cur->next) {
+	list_for_each_entry(cur, &trans, list) {
 		if (cur == tc) {
 			spin_unlock(&translock);
-			return res;
+			return -EBUSY;
 		}
 	}
 
-	tc->next = trans;
-	trans = tc;
+	list_add(&tc->list, &trans);
 	printk("Registered codec translator '%s' with %d transcoders (srcs=%08x, dsts=%08x)\n", 
 	       tc->name, tc->numchannels, tc->srcfmts, tc->dstfmts);
-	res = 0;
 	spin_unlock(&translock);
 
-	return res;
+	return 0;
 }
 
 /* Unregister a transcoder */
 int zt_transcoder_unregister(struct zt_transcoder *tc) 
 {
-	struct zt_transcoder *cur, *prev;
-	int res = -EINVAL;
+	struct zt_transcoder *cur, *next;
 
 	spin_lock(&translock);
-	for (cur = trans, prev = NULL; cur; prev = cur, cur = cur->next) {
-		if (cur == tc)
+	list_for_each_entry_safe(cur, next, &trans, list) {
+		if (cur == tc) {
+			list_del_init(&cur->list);
 			break;
+		}
 	}
 
 	if (!cur) {
 		spin_unlock(&translock);
-		return res;
-	}
-
-	if (prev)
-		prev->next = tc->next;
-	else
-		trans = tc->next;
-	tc->next = NULL;
+		return -EINVAL;
+	}
+
 	printk("Unregistered codec translator '%s' with %d transcoders (srcs=%08x, dsts=%08x)\n", 
 	       tc->name, tc->numchannels, tc->srcfmts, tc->dstfmts);
-	res = 0;
 	spin_unlock(&translock);
 
-	return res;
+	return 0;
 }
 
 /* Alert a transcoder */
@@ -245,7 +238,7 @@
 	    ((*ztc)->dstfmt != zth->dstfmt)) {
 		/* Find new transcoder */
 		spin_lock(&translock);
-		for (tc = trans; tc && !newztc; tc = tc->next) {
+		list_for_each_entry(tc, &trans, list) {
 			if (!(tc->srcfmts & zth->srcfmt))
 				continue;
 
@@ -307,7 +300,11 @@
 		return -EFAULT;
 
 	spin_lock(&translock);
-	for (tc = trans, x = info.tcnum; tc && x; tc = tc->next, x--);
+	x = info.tcnum;
+	list_for_each_entry(tc, &trans, list) {
+		if (!x--)
+			break;
+	}
 	spin_unlock(&translock);
 
 	if (!tc)



More information about the zaptel-commits mailing list