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<unistd.h>
00039 
00040 #ifndef true
00041 # define true 1
00042 #endif
00043 #ifndef false
00044 # define false 0
00045 #endif
00046 
00047 typedef struct link link_t;
00048 
00050 struct link {
00051         link_t *prev;   
00052         link_t *next;   
00053 };
00054 
00059 #define LIST_INITIALIZE(name)           link_t name = { .prev = &name, .next = &name }
00060 
00067 static inline void link_initialize(link_t *link)
00068 {
00069         link->prev = NULL;
00070         link->next = NULL;
00071 }
00072 
00079 static inline void list_initialize(link_t *head)
00080 {
00081         head->prev = head;
00082         head->next = head;
00083 }
00084 
00092 static inline void list_prepend(link_t *link, link_t *head)
00093 {
00094         link->next = head->next;
00095         link->prev = head;
00096         head->next->prev = link;
00097         head->next = link;
00098 }
00099 
00107 static inline void list_append(link_t *link, link_t *head)
00108 {
00109         link->prev = head->prev;
00110         link->next = head;
00111         head->prev->next = link;
00112         head->prev = link;
00113 }
00114 
00121 static inline void list_remove(link_t *link)
00122 {
00123         link->next->prev = link->prev;
00124         link->prev->next = link->next;
00125         link_initialize(link);
00126 }
00127 
00134 static inline int list_empty(link_t *head)
00135 {
00136         return head->next == head ? true : false;
00137 }
00138 
00139 
00150 static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
00151 {
00152         link_t *hlp;
00153 
00154         part1->prev->next = part2;
00155         part2->prev->next = part1;      
00156         hlp = part1->prev;
00157         part1->prev = part2->prev;
00158         part2->prev = hlp;
00159 }
00160 
00161 
00169 static inline void headless_list_split(link_t *part1, link_t *part2)
00170 {
00171         headless_list_split_or_concat(part1, part2);
00172 }
00173 
00181 static inline void headless_list_concat(link_t *part1, link_t *part2)
00182 {
00183         headless_list_split_or_concat(part1, part2);
00184 }
00185 
00186 #define list_get_instance(link,type,member) (type *)(((char *)(link))-((char *)&(((type *)NULL)->member)))
00187 
00188 extern int list_member(const link_t *link, const link_t *head);
00189 extern void list_concat(link_t *head1, link_t *head2);
00190 
00191 #endif
00192 
00193 

Generated on Sun Jun 18 18:00:18 2006 for HelenOS Userspace (ia64) by  doxygen 1.4.6