r4854 - in trunk/src/target/opkg: libopkg tests

tick at docs.openmoko.org tick at docs.openmoko.org
Mon Dec 8 09:09:19 CET 2008


Author: tick
Date: 2008-12-08 09:09:19 +0100 (Mon, 08 Dec 2008)
New Revision: 4854

Modified:
   trunk/src/target/opkg/libopkg/active_list.c
   trunk/src/target/opkg/libopkg/active_list.h
   trunk/src/target/opkg/tests/opkg_active_list_test.c
Log:
opkg: refactory active_list_next  remove unnecessary field.


Modified: trunk/src/target/opkg/libopkg/active_list.c
===================================================================
--- trunk/src/target/opkg/libopkg/active_list.c	2008-12-08 08:09:02 UTC (rev 4853)
+++ trunk/src/target/opkg/libopkg/active_list.c	2008-12-08 08:09:19 UTC (rev 4854)
@@ -23,7 +23,6 @@
 void active_list_init(struct active_list *ptr) {
     INIT_LIST_HEAD(&ptr->node);
     INIT_LIST_HEAD(&ptr->depend);
-    ptr->walked=0;
     ptr->depended = NULL;
 }
 
@@ -31,38 +30,23 @@
  */ 
 struct active_list * active_list_next(struct active_list *head, struct active_list *ptr) {
     struct active_list *next=NULL;
-    if (!head || !ptr) {
+    if (!head) {
         fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr);
         return NULL;
     }
-    if (ptr == head) {
-        head->walked = !head->walked;
-        next = list_entry(ptr->node.next, struct active_list, node);
-        if (next == head)
-            return NULL;
-        return active_list_next(head, next);
+    if (!ptr)
+        ptr = head;
+    next = list_entry(ptr->node.next, struct active_list, node);
+    if (next == head ) {
+        return NULL;
     }
-    if (ptr->depend.next != &ptr->depend) {
-        next = list_entry(ptr->depend.next, struct active_list, node);
-        if (head->walked != next->walked) {
-            ptr->walked = head->walked;
-            return active_list_next(head, next);
-        }
-    } 
-    if (ptr->walked != head->walked) {
-        ptr->walked = head->walked;
-        return ptr;
-    }
-
-    if (ptr->depended && ptr->node.next == &ptr->depended->depend ) {
+    if (ptr->depended && &ptr->depended->depend == ptr->node.next ) {
         return ptr->depended;
     }
-
-    if (ptr->node.next != &head->node) {
-        next = list_entry(ptr->node.next, struct active_list, node);
-        return active_list_next(head, next);
-    } 
-    return NULL;
+    while (next->depend.next != &next->depend) {
+        next = list_entry(next->depend.next, struct active_list, node); 
+    }
+    return next;
 }
 
 
@@ -78,4 +62,5 @@
 void active_list_add(struct active_list *head, struct active_list *node) {
     list_del_init(&node->node);
     list_add_tail(&node->node, &head->node);
+    node->depended  = head;
 }

Modified: trunk/src/target/opkg/libopkg/active_list.h
===================================================================
--- trunk/src/target/opkg/libopkg/active_list.h	2008-12-08 08:09:02 UTC (rev 4853)
+++ trunk/src/target/opkg/libopkg/active_list.h	2008-12-08 08:09:19 UTC (rev 4854)
@@ -23,7 +23,6 @@
 struct active_list {
     struct list_head node;
     struct list_head depend;
-    char walked;
     struct active_list *depended;
 };
 

Modified: trunk/src/target/opkg/tests/opkg_active_list_test.c
===================================================================
--- trunk/src/target/opkg/tests/opkg_active_list_test.c	2008-12-08 08:09:02 UTC (rev 4853)
+++ trunk/src/target/opkg/tests/opkg_active_list_test.c	2008-12-08 08:09:19 UTC (rev 4854)
@@ -110,7 +110,7 @@
         printf ("%s ",test->str);
     }
     printf("\n");
-    for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
+    for(ptr = active_list_next(&head, NULL); ptr ;ptr = active_list_next(&head, ptr)) {
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);
     }




More information about the commitlog mailing list