Clean up some compilation warnings for VxWorks
[yaffs2.git] / direct / yaffs_list.h
1 /*
2  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License version 2.1 as
11  * published by the Free Software Foundation.
12  *
13  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
14  */
15
16 /*
17  * This file is just holds extra declarations of macros that would normally
18  * be providesd in the Linux kernel. These macros have been written from
19  * scratch but are functionally equivalent to the Linux ones.
20  *
21  */
22
23 #ifndef __YAFFS_LIST_H__
24 #define __YAFFS_LIST_H__
25
26
27 /*
28  * This is a simple doubly linked list implementation that matches the
29  * way the Linux kernel doubly linked list implementation works.
30  */
31
32 struct list_head {
33         struct list_head *next; /* next in chain */
34         struct list_head *prev; /* previous in chain */
35 };
36
37
38 /* Initialise a static list */
39 #ifdef LIST_HEAD
40 #undef LIST_HEAD
41 #endif
42
43 #define LIST_HEAD(name) \
44 struct list_head name = { &(name), &(name)}
45
46
47
48 /* Initialise a list head to an empty list */
49 #define INIT_LIST_HEAD(p) \
50 do { \
51         (p)->next = (p);\
52         (p)->prev = (p); \
53 } while (0)
54
55
56 /* Add an element to a list */
57 static inline void list_add(struct list_head *new_entry,
58                                 struct list_head *list)
59 {
60         struct list_head *list_next = list->next;
61
62         list->next = new_entry;
63         new_entry->prev = list;
64         new_entry->next = list_next;
65         list_next->prev = new_entry;
66
67 }
68
69 static inline void list_add_tail(struct list_head *new_entry,
70                                  struct list_head *list)
71 {
72         struct list_head *list_prev = list->prev;
73
74         list->prev = new_entry;
75         new_entry->next = list;
76         new_entry->prev = list_prev;
77         list_prev->next = new_entry;
78
79 }
80
81
82 /* Take an element out of its current list, with or without
83  * reinitialising the links.of the entry*/
84 static inline void list_del(struct list_head *entry)
85 {
86         struct list_head *list_next = entry->next;
87         struct list_head *list_prev = entry->prev;
88
89         list_next->prev = list_prev;
90         list_prev->next = list_next;
91
92 }
93
94 static inline void list_del_init(struct list_head *entry)
95 {
96         list_del(entry);
97         entry->next = entry->prev = entry;
98 }
99
100
101 /* Test if the list is empty */
102 static inline int list_empty(struct list_head *entry)
103 {
104         return (entry->next == entry);
105 }
106
107
108 /* list_entry takes a pointer to a list entry and offsets it to that
109  * we can find a pointer to the object it is embedded in.
110  */
111
112
113 #define list_entry(entry, type, member) \
114         ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
115
116
117 /* list_for_each and list_for_each_safe  iterate over lists.
118  * list_for_each_safe uses temporary storage to make the list delete safe
119  */
120
121 #define list_for_each(itervar, list) \
122         for (itervar = (list)->next; itervar != (list); itervar = itervar->next)
123
124 #define list_for_each_safe(itervar, save_var, list) \
125         for (itervar = (list)->next, save_var = (list)->next->next; \
126                 itervar != (list); \
127                 itervar = save_var, save_var = save_var->next)
128
129
130 #endif