nfs-ganesha 1.4

nlm_list.h

Go to the documentation of this file.
00001 /*
00002  * Copyright IBM Corporation, 2010
00003  *  Contributor: Aneesh Kumar K.v  <aneesh.kumar@linux.vnet.ibm.com>
00004  *
00005  *
00006  * This software is a server that implements the NFS protocol.
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 3 of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00021  *
00022  * ---------------------------------------
00023  *
00024  *
00025  */
00026 
00027 #ifndef _NLM_LIST_H
00028 #define _NLM_LIST_H
00029 
00030 #include <stddef.h>
00031 
00032 struct glist_head
00033 {
00034   struct glist_head *next;
00035   struct glist_head *prev;
00036 };
00037 
00038 #define GLIST_HEAD_INIT(name) { &(name), &(name) }
00039 
00040 #define GLIST_HEAD(name) \
00041         struct glist_head name = GLIST_HEAD_INIT(name)
00042 
00043 /*FIXME!!! grand hack due to mysql conflict name glist*/
00044 
00045 static inline void init_glist(struct glist_head *head) /* XXX glist_init? */
00046 {
00047   head->next = head;
00048   head->prev = head;
00049 }
00050 
00051 /* Add the new element between left and right */
00052 static inline void __glist_add(struct glist_head *left, struct glist_head *right,
00053                                struct glist_head *new)
00054 {
00055   new->prev = left;
00056   new->next = right;
00057   left->next = new;
00058   right->prev = new;
00059 }
00060 
00061 static inline void glist_add_tail(struct glist_head *head, struct glist_head *new)
00062 {
00063 
00064   __glist_add(head->prev, head, new);
00065 }
00066 
00067 /* add after the specified entry*/
00068 static inline void glist_add(struct glist_head *head, struct glist_head *new)
00069 {
00070   __glist_add(head, head->next, new);
00071 }
00072 
00073 static inline void glist_del(struct glist_head *node)
00074 {
00075   struct glist_head *left = node->prev;
00076   struct glist_head *right = node->next;
00077   if(left != NULL)
00078     left->next = right;
00079   if(right != NULL)
00080     right->prev = left;
00081   node->next = NULL;
00082   node->prev = NULL;
00083 }
00084 
00085 static inline int glist_empty(struct glist_head *head)
00086 {
00087   return head->next == head;
00088 }
00089 
00090 static inline void glist_add_list_tail(struct glist_head *list, struct glist_head *new)
00091 {
00092   struct glist_head *first = new->next;
00093   struct glist_head *last = new->prev;
00094 
00095   if(glist_empty(new))
00096     {
00097       /* nothing to add */
00098       return;
00099     }
00100 
00101   first->prev = list->prev;
00102   list->prev->next = first;
00103 
00104   last->next = list;
00105   list->prev = last;
00106 }
00107 
00108 #define glist_for_each(node, head) \
00109         for(node = (head)->next; node != head; node = node->next)
00110 
00111 #define container_of(addr, type, member) ({                     \
00112         const typeof( ((type *)0)->member ) *__mptr = (addr);   \
00113         (type *)( (char *)__mptr - offsetof(type,member) );})
00114 
00115 #define glist_first_entry(head, type, member) \
00116         ((head)->next != (head) ? \
00117           container_of((head)->next, type, member) : NULL)
00118 
00119 #define glist_entry(node, type, member) \
00120         container_of(node, type, member)
00121 
00122 #define glist_for_each_safe(node, noden, head)                      \
00123   for (node = (head)->next, noden = node->next; node != (head);     \
00124        node = noden, noden = node->next)
00125 
00126 #endif                          /* _NLM_LIST_H */