list.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2004 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __LIST_H__
00036 #define __LIST_H__
00037 
00038 #include <arch/types.h>
00039 #include <typedefs.h>
00040 
00042 struct link {
00043         link_t *prev;   
00044         link_t *next;   
00045 };
00046 
00051 #define LIST_INITIALIZE(name)           link_t name = { .prev = &name, .next = &name }
00052 
00059 static inline void link_initialize(link_t *link)
00060 {
00061         link->prev = NULL;
00062         link->next = NULL;
00063 }
00064 
00071 static inline void list_initialize(link_t *head)
00072 {
00073         head->prev = head;
00074         head->next = head;
00075 }
00076 
00084 static inline void list_prepend(link_t *link, link_t *head)
00085 {
00086         link->next = head->next;
00087         link->prev = head;
00088         head->next->prev = link;
00089         head->next = link;
00090 }
00091 
00099 static inline void list_append(link_t *link, link_t *head)
00100 {
00101         link->prev = head->prev;
00102         link->next = head;
00103         head->prev->next = link;
00104         head->prev = link;
00105 }
00106 
00113 static inline void list_remove(link_t *link)
00114 {
00115         link->next->prev = link->prev;
00116         link->prev->next = link->next;
00117         link_initialize(link);
00118 }
00119 
00126 static inline bool list_empty(link_t *head)
00127 {
00128         return head->next == head ? true : false;
00129 }
00130 
00131 
00142 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
00143 {
00144         link_t *hlp;
00145 
00146         part1->prev->next = part2;
00147         part2->prev->next = part1;      
00148         hlp = part1->prev;
00149         part1->prev = part2->prev;
00150         part2->prev = hlp;
00151 }
00152 
00153 
00161 static inline void headless_list_split(link_t *part1, link_t *part2)
00162 {
00163         headless_list_split_or_concat(part1, part2);
00164 }
00165 
00173 static inline void headless_list_concat(link_t *part1, link_t *part2)
00174 {
00175         headless_list_split_or_concat(part1, part2);
00176 }
00177 
00178 #define list_get_instance(link,type,member) (type *)(((__u8*)(link))-((__u8*)&(((type *)NULL)->member)))
00179 
00180 extern bool list_member(const link_t *link, const link_t *head);
00181 extern void list_concat(link_t *head1, link_t *head2);
00182 
00183 #endif
00184 

Generated on Sun Jun 18 17:01:57 2006 for HelenOS Kernel (mips32) by  doxygen 1.4.6