1 /* drm_linux_list.h -- linux list functions for the BSDs.
2 * Created: Mon Apr 7 14:30:16 1999 by anholt@FreeBSD.org
5 * Copyright 2003 Eric Anholt
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
28 * Eric Anholt <anholt@FreeBSD.org>
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #ifndef _DRM_LINUX_LIST_H_
36 #define _DRM_LINUX_LIST_H_
39 struct list_head *next, *prev;
42 #define list_entry(ptr, type, member) container_of(ptr,type,member)
43 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
45 static __inline__ void
46 INIT_LIST_HEAD(struct list_head *head) {
52 list_empty(struct list_head *head) {
53 return (head)->next == head;
56 static __inline__ void
57 list_add(struct list_head *new, struct list_head *head) {
58 (head)->next->prev = new;
59 (new)->next = (head)->next;
64 static __inline__ void
65 list_add_tail(struct list_head *entry, struct list_head *head) {
66 (entry)->prev = (head)->prev;
68 (head)->prev->next = entry;
72 static __inline__ void
73 list_del(struct list_head *entry) {
74 (entry)->next->prev = (entry)->prev;
75 (entry)->prev->next = (entry)->next;
78 static __inline__ void
79 list_del_init(struct list_head *entry) {
80 (entry)->next->prev = (entry)->prev;
81 (entry)->prev->next = (entry)->next;
82 INIT_LIST_HEAD(entry);
85 #define list_for_each(entry, head) \
86 for (entry = (head)->next; entry != head; entry = (entry)->next)
88 #define list_for_each_prev(entry, head) \
89 for (entry = (head)->prev; entry != (head); \
92 #define list_for_each_safe(entry, temp, head) \
93 for (entry = (head)->next, temp = (entry)->next; \
95 entry = temp, temp = entry->next)
98 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
99 * @pos: the type * to use as a loop cursor.
100 * @n: another type * to use as temporary storage
101 * @head: the head for your list.
102 * @member: the name of the list_struct within the struct.
104 #define list_for_each_entry_safe(pos, n, head, member) \
105 for (pos = list_entry((head)->next, __typeof(*pos), member), \
106 n = list_entry(pos->member.next, __typeof(*pos), member); \
107 &pos->member != (head); \
108 pos = n, n = list_entry(n->member.next, __typeof(*n), member))
110 #endif /* _DRM_LINUX_LIST_H_ */