PERFORCE change 100631 for review

Paolo Pisati piso at FreeBSD.org
Wed Jul 5 15:16:48 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=100631

Change 100631 by piso at piso_newluxor on 2006/07/05 15:15:46

	Convert dll to queue(3).

Affected files ...

.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#10 edit
.. //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#10 edit

Differences ...

==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.c#10 (text+ko) ====

@@ -61,7 +61,7 @@
 
 /* protocol and userland module handlers chains */
 struct chain handler_chain;
-struct dll *dll_chain;
+SLIST_HEAD(dll_chain, dll) dll_chain = SLIST_HEAD_INITIALIZER(foo); 
 
 #ifdef _KERNEL
 
@@ -257,55 +257,38 @@
 
 /* dll manipulation code - this code is not thread safe... */
 
-static int
-_attach_dll(struct dll **b, struct dll *p) {
-	int i = 0;
+int
+attach_dll(struct dll *p) {
+	struct dll *b;
 
-	p->next = NULL; /* i'm paranoid... */
-	for(; *b != NULL; b = &((*b)->next), i++)
-		if (!strncmp((*b)->name, p->name, DLL_LEN))
+	SLIST_FOREACH(b, &dll_chain, next) {
+		if (!strncmp(b->name, p->name, DLL_LEN))
 			return (EHDCON); /* dll name conflict */
+	}
 	/* end of list, insert here */
-	*b = p;
+	SLIST_INSERT_HEAD(&dll_chain, p, next);
 	return (OK);
 }
 
-static void *
-_detach_dll(struct dll **b, char *p) {
-	void *err = NULL;
+void *
+detach_dll(char *p) {
+	struct dll *b = NULL, *b_tmp;
+	void *error = NULL;
 
-	for(; *b != NULL; b = &((*b)->next))
-		if (!strncmp((*b)->name, p, DLL_LEN)) {
-			err = *b;
-			*b = (*b)->next; 						
+	SLIST_FOREACH_SAFE(b, &dll_chain, next, b_tmp)
+		if (!strncmp(b->name, p, DLL_LEN)) {
+			SLIST_REMOVE(&dll_chain, b, dll, next); 
+			error = b;
 			break;
 		}
-	return (err);
-}
-
-int
-attach_dll(struct dll *p) {
-	int i;
-
-	i = _attach_dll(&dll_chain, p);
-	return (i);
-}
-
-void *
-detach_dll(char *p) {
-	void *i;
-
-	i = _detach_dll(&dll_chain, p);
-	return (i);
+	return (error);
 }
 
 struct dll *
 walk_dll_chain(void) {
-	struct dll *t, **b = &dll_chain;
+	struct dll *t;
 
-	for(t = *b; *b != NULL;) {       
-		*b = (*b)->next; 		
-		break;
-	}
+	t = SLIST_FIRST(&dll_chain);
+	SLIST_REMOVE_HEAD(&dll_chain, next);
 	return (t);
 }

==== //depot/projects/soc2005/libalias/sys/netinet/libalias/alias_mod.h#10 (text+ko) ====

@@ -86,12 +86,6 @@
 	struct rwlock   rw;
 };
 
-struct dll_chain {
-	void            *chain;	
-	// XXX - what if a process with 2 threads manipulate the
-	// libalias dll list? we still need a lock here...
-};
-
 /* 
  * Used only in userland when libalias needs to keep track of all
  * module loaded. In kernel land (kld mode) we don't need to care
@@ -107,7 +101,7 @@
 					 * to any symbols from a loaded module 					 
 					 * via dlsym(). 
 					 */
-	struct dll      *next;
+	SLIST_ENTRY(dll)        next;
 };
 
 /* Functions used with protocol handlers. */


More information about the p4-projects mailing list