Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / sys / dev / drm / drm_linux_list.h
1 /* drm_linux_list.h -- linux list functions for the BSDs.
2  * Created: Mon Apr 7 14:30:16 1999 by anholt@FreeBSD.org
3  */
4 /*-
5  * Copyright 2003 Eric Anholt
6  * All Rights Reserved.
7  *
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:
14  *
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
17  * Software.
18  *
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.
26  *
27  * Authors:
28  *    Eric Anholt <anholt@FreeBSD.org>
29  *
30  */
31
32 #include <sys/cdefs.h>
33
34 #ifndef _DRM_LINUX_LIST_H_
35 #define _DRM_LINUX_LIST_H_
36
37 struct list_head {
38         struct list_head *next, *prev;
39 };
40
41 #define list_entry(ptr, type, member) container_of(ptr,type,member)
42 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
43
44 static __inline__ void
45 INIT_LIST_HEAD(struct list_head *head) {
46         (head)->next = head;
47         (head)->prev = head;
48 }
49
50 static __inline__ int
51 list_empty(struct list_head *head) {
52         return (head)->next == head;
53 }
54
55 static __inline__ void
56 list_add(struct list_head *new, struct list_head *head) {
57         (head)->next->prev = new;
58         (new)->next = (head)->next;
59         (new)->prev = head;
60         (head)->next = new;
61 }
62
63 static __inline__ void
64 list_add_tail(struct list_head *entry, struct list_head *head) {
65         (entry)->prev = (head)->prev;
66         (entry)->next = head;
67         (head)->prev->next = entry;
68         (head)->prev = entry;
69 }
70
71 static __inline__ void
72 list_del(struct list_head *entry) {
73         (entry)->next->prev = (entry)->prev;
74         (entry)->prev->next = (entry)->next;
75 }
76
77 static __inline__ void
78 list_del_init(struct list_head *entry) {
79         (entry)->next->prev = (entry)->prev;
80         (entry)->prev->next = (entry)->next;
81         INIT_LIST_HEAD(entry);
82 }
83
84 #define list_for_each(entry, head)                              \
85     for (entry = (head)->next; entry != head; entry = (entry)->next)
86
87 #define list_for_each_prev(entry, head) \
88         for (entry = (head)->prev; entry != (head); \
89                 entry = entry->prev)
90
91 #define list_for_each_safe(entry, temp, head)                   \
92     for (entry = (head)->next, temp = (entry)->next;            \
93         entry != head;                                          \
94         entry = temp, temp = entry->next)
95
96 /**
97  * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
98  * @pos:        the type * to use as a loop cursor.
99  * @n:          another type * to use as temporary storage
100  * @head:       the head for your list.
101  * @member:     the name of the list_struct within the struct.
102  */
103 #define list_for_each_entry_safe(pos, n, head, member)                  \
104         for (pos = list_entry((head)->next, __typeof(*pos), member),    \
105             n = list_entry(pos->member.next, __typeof(*pos), member);   \
106             &pos->member != (head);                                     \
107             pos = n, n = list_entry(n->member.next, __typeof(*n), member))
108
109 #endif /* _DRM_LINUX_LIST_H_ */