1 /* active_list.h - the opkg package management system
3 Tick Chen <tick@openmoko.com>
5 Copyright (C) 2008 Openmoko Inc.
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
19 #include "active_list.h"
25 void active_list_init(struct active_list *ptr) {
26 INIT_LIST_HEAD(&ptr->node);
27 INIT_LIST_HEAD(&ptr->depend);
33 struct active_list * active_list_next(struct active_list *head, struct active_list *ptr) {
34 struct active_list *next=NULL;
36 fprintf(stderr, "active_list_next head = %p, ptr = %p invalid value!!\n", head, ptr);
41 next = list_entry(ptr->node.next, struct active_list, node);
45 if ( ptr->depended && &ptr->depended->depend == ptr->node.next ) {
48 while ( next->depend.next != &next->depend ) {
49 next = list_entry(next->depend.next, struct active_list, node);
55 struct active_list * active_list_prev(struct active_list *head, struct active_list *ptr) {
56 struct active_list *prev=NULL;
58 fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr);
63 if ( ptr->depend.prev != &ptr->depend ) {
64 prev = list_entry(ptr->depend.prev, struct active_list, node);
67 if ( ptr->depended && ptr->depended != head && &ptr->depended->depend == ptr->node.prev ) {
68 prev = list_entry(ptr->depended->node.prev, struct active_list, node);
70 prev = list_entry(ptr->node.prev, struct active_list, node);
76 static void list_head_clear (struct list_head *head) {
77 struct active_list *next;
78 struct list_head *n, *ptr;
81 list_for_each_safe(ptr, n , head) {
82 next = list_entry(ptr, struct active_list, node);
83 if (next->depend.next != &next->depend) {
84 list_head_clear(&next->depend);
86 active_list_init(next);
89 void active_list_clear(struct active_list *head) {
90 list_head_clear(&head->node);
91 if (head->depend.next != &head->depend) {
92 list_head_clear(&head->depend);
94 active_list_init(head);
97 void active_list_add_depend(struct active_list *node, struct active_list *depend) {
98 list_del_init(&depend->node);
99 list_add_tail(&depend->node, &node->depend);
100 depend->depended = node;
103 void active_list_add(struct active_list *head, struct active_list *node) {
104 list_del_init(&node->node);
105 list_add_tail(&node->node, &head->node);
106 node->depended = head;
109 struct active_list * active_list_head_new() {
110 struct active_list * head = calloc(1, sizeof(struct active_list));
111 active_list_init(head);
115 void active_list_head_delete(struct active_list *head) {
116 active_list_clear(head);