opkg: implment active_list_clear()
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:32:47 +0000 (05:32 +0000)
committerticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Mon, 15 Dec 2008 05:32:47 +0000 (05:32 +0000)
git-svn-id: http://opkg.googlecode.com/svn/trunk@170 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358

libopkg/active_list.c
tests/opkg_active_list_test.c

index e297cfca4d7a63b6bcc5eecbef29a9605248f6c2..85444400f23979bd0aac46784923f26699d6f697 100644 (file)
@@ -71,7 +71,22 @@ struct active_list * active_list_prev(struct active_list *head, struct active_li
     return prev;
 }
 
     return prev;
 }
 
+static void list_head_clear (struct list_head *head) {
+    struct active_list *next;
+    struct list_head *n, *ptr;
+    if (!head)
+        return;
+    list_for_each_safe(ptr, n , head) {
+        next = list_entry(ptr, struct active_list, node);
+        if (next->depend.next != &next->depend) {
+            list_head_clear(&next->depend);
+        }
+        list_del_init(&next->node);
+        next->depended = NULL;
+    }
+}
 void active_list_clear(struct active_list *head) {
 void active_list_clear(struct active_list *head) {
+    list_head_clear(&head->node);
 }
 
 void active_list_add_depend(struct active_list *node, struct active_list *depend) {
 }
 
 void active_list_add_depend(struct active_list *node, struct active_list *depend) {
index 1e216450fe8d3700359512d8da9308e313f6eaea..77819b09183a99bc30dd4c661cf360b8183a19bf 100644 (file)
@@ -111,7 +111,8 @@ int main (void) {
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);
     }
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);
     }
-    printf("\npos order: ");
+    printf("\nafter clear: ");
+    active_list_clear(&head);
     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);
     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);