[asterisk-commits] file: trunk r74703 - in /trunk: include/asterisk/udptl.h main/udptl.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 11 15:07:08 CDT 2007


Author: file
Date: Wed Jul 11 15:07:07 2007
New Revision: 74703

URL: http://svn.digium.com/view/asterisk?view=rev&rev=74703
Log:
Use linkedlist macros for UDPTL protocol list.

Modified:
    trunk/include/asterisk/udptl.h
    trunk/main/udptl.c

Modified: trunk/include/asterisk/udptl.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/udptl.h?view=diff&rev=74703&r1=74702&r2=74703
==============================================================================
--- trunk/include/asterisk/udptl.h (original)
+++ trunk/include/asterisk/udptl.h Wed Jul 11 15:07:07 2007
@@ -42,7 +42,7 @@
 	/* Set UDPTL peer */
 	int (* const set_udptl_peer)(struct ast_channel *chan, struct ast_udptl *peer);
 	const char * const type;
-	struct ast_udptl_protocol *next;
+	AST_RWLIST_ENTRY(ast_udptl_protocol) list;
 };
 
 struct ast_udptl;

Modified: trunk/main/udptl.c
URL: http://svn.digium.com/view/asterisk/trunk/main/udptl.c?view=diff&rev=74703&r1=74702&r2=74703
==============================================================================
--- trunk/main/udptl.c (original)
+++ trunk/main/udptl.c Wed Jul 11 15:07:07 2007
@@ -170,7 +170,7 @@
 	udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1];
 };
 
-static struct ast_udptl_protocol *protos;
+static AST_RWLIST_HEAD_STATIC(protos, ast_udptl_protocol);
 
 static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, int len);
 static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, uint8_t *ifp, int ifp_len);
@@ -949,52 +949,40 @@
 
 void ast_udptl_proto_unregister(struct ast_udptl_protocol *proto)
 {
+	AST_RWLIST_WRLOCK(&protos);
+	AST_RWLIST_REMOVE(&protos, proto, list);
+	AST_RWLIST_UNLOCK(&protos);
+}
+
+int ast_udptl_proto_register(struct ast_udptl_protocol *proto)
+{
 	struct ast_udptl_protocol *cur;
-	struct ast_udptl_protocol *prev;
-
-	cur = protos;
-	prev = NULL;
-	while (cur) {
-		if (cur == proto) {
-			if (prev)
-				prev->next = proto->next;
-			else
-				protos = proto->next;
-			return;
-		}
-		prev = cur;
-		cur = cur->next;
-	}
-}
-
-int ast_udptl_proto_register(struct ast_udptl_protocol *proto)
-{
-	struct ast_udptl_protocol *cur;
-
-	cur = protos;
-	while (cur) {
+
+	AST_RWLIST_WRLOCK(&protos);
+	AST_RWLIST_TRAVERSE(&protos, cur, list) {
 		if (cur->type == proto->type) {
 			ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
+			AST_RWLIST_UNLOCK(&protos);
 			return -1;
 		}
-		cur = cur->next;
-	}
-	proto->next = protos;
-	protos = proto;
+	}
+	AST_RWLIST_INSERT_TAIL(&protos, proto, list);
+	AST_RWLIST_UNLOCK(&protos);
 	return 0;
 }
 
 static struct ast_udptl_protocol *get_proto(struct ast_channel *chan)
 {
-	struct ast_udptl_protocol *cur;
-
-	cur = protos;
-	while (cur) {
+	struct ast_udptl_protocol *cur = NULL;
+
+	AST_RWLIST_RDLOCK(&protos);
+	AST_RWLIST_TRAVERSE(&protos, cur, list) {
 		if (cur->type == chan->tech->type)
-			return cur;
-		cur = cur->next;
-	}
-	return NULL;
+			break;
+	}
+	AST_RWLIST_UNLOCK(&protos);
+
+	return cur;
 }
 
 int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc)




More information about the asterisk-commits mailing list