Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | /* * include/asm-s390/queue.h * * S390 version * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) * * A little set of queue utilies. */ #include <linux/stddef.h> #include <asm/types.h> typedef struct queue { struct queue *next; } queue; typedef queue list; typedef struct { queue *head; queue *tail; } qheader; static __inline__ void init_queue(qheader *qhead) { memset(qhead,0,sizeof(*qhead)); } static __inline__ void enqueue_tail(qheader *qhead,queue *member) { queue *tail=qhead->tail; member->next=NULL; if(member) { if(tail) tail->next=member; else qhead->head=member; qhead->tail=member; member->next=NULL; } } static __inline__ queue *dequeue_head(qheader *qhead) { queue *head=qhead->head,*next_head; if(head) { next_head=head->next; qhead->head=next_head; if(!next_head) qhead->tail=NULL; } return(head); } static __inline__ void init_list(list **lhead) { *lhead=NULL; } static __inline__ void add_to_list(list **lhead,list *member) { member->next=*lhead; *lhead=member; } static __inline__ list *remove_listhead(list **lhead) { list *oldhead=*lhead; if(oldhead) *lhead=(*lhead)->next; return(oldhead); } static __inline__ void add_to_list_tail(list **lhead,list *member) { list *curr,*prev; if(*lhead==NULL) *lhead=member; else { prev=*lhead; for(curr=(*lhead)->next;curr!=NULL;curr=curr->next) prev=curr; prev->next=member; } } static __inline__ void add_to_list_tail_null(list **lhead,list *member) { member->next=NULL; add_to_list_tail_null(lhead,member); } static __inline__ int is_in_list(list *lhead,list *member) { list *curr; for(curr=lhead;curr!=NULL;curr=curr->next) if(curr==member) return(TRUE); return(FALSE); } static __inline__ int get_prev(list *lhead,list *member,list **prev) { list *curr; *prev=NULL; for(curr=lhead;curr!=NULL;curr=curr->next) { if(curr==member) return(TRUE); *prev=curr; } *prev=NULL; return(FALSE); } static __inline__ int remove_from_list(list **lhead,list *member) { list *prev; if(get_prev(*lhead,member,&prev)) { if(prev) prev->next=member->next; else *lhead=member->next; return(TRUE); } return(FALSE); } static __inline__ int remove_from_queue(qheader *qhead,queue *member) { queue *prev; if(get_prev(qhead->head,(list *)member,(list **)&prev)) { if(prev) { prev->next=member->next; if(prev->next==NULL) qhead->tail=prev; } else { if(qhead->head==qhead->tail) qhead->tail=NULL; qhead->head=member->next; } return(TRUE); } return(FALSE); } |