drm_linux_list.h revision 189913
1130331Sanholt/* drm_linux_list.h -- linux list functions for the BSDs.
2145132Sanholt * Created: Mon Apr 7 14:30:16 1999 by anholt@FreeBSD.org
3145132Sanholt */
4139749Simp/*-
5130331Sanholt * Copyright 2003 Eric Anholt
6130331Sanholt * All Rights Reserved.
7130331Sanholt *
8130331Sanholt * Permission is hereby granted, free of charge, to any person obtaining a
9130331Sanholt * copy of this software and associated documentation files (the "Software"),
10130331Sanholt * to deal in the Software without restriction, including without limitation
11130331Sanholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12130331Sanholt * and/or sell copies of the Software, and to permit persons to whom the
13130331Sanholt * Software is furnished to do so, subject to the following conditions:
14130331Sanholt *
15130331Sanholt * The above copyright notice and this permission notice (including the next
16130331Sanholt * paragraph) shall be included in all copies or substantial portions of the
17130331Sanholt * Software.
18130331Sanholt *
19130331Sanholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20130331Sanholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21130331Sanholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22130331Sanholt * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23130331Sanholt * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24130331Sanholt * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25130331Sanholt * OTHER DEALINGS IN THE SOFTWARE.
26130331Sanholt *
27130331Sanholt * Authors:
28130331Sanholt *    Eric Anholt <anholt@FreeBSD.org>
29130331Sanholt *
30130331Sanholt */
31130331Sanholt
32152909Sanholt#include <sys/cdefs.h>
33152909Sanholt__FBSDID("$FreeBSD: head/sys/dev/drm/drm_linux_list.h 189913 2009-03-17 03:49:24Z rnoland $");
34152909Sanholt
35130331Sanholtstruct list_head {
36130331Sanholt	struct list_head *next, *prev;
37130331Sanholt};
38130331Sanholt
39130331Sanholt/* Cheat, assume the list_head is at the start of the struct */
40130331Sanholt#define list_entry(entry, type, member)	(type *)(entry)
41130331Sanholt
42130331Sanholtstatic __inline__ void
43130331SanholtINIT_LIST_HEAD(struct list_head *head) {
44130331Sanholt	(head)->next = head;
45130331Sanholt	(head)->prev = head;
46130331Sanholt}
47130331Sanholt
48130331Sanholtstatic __inline__ int
49130331Sanholtlist_empty(struct list_head *head) {
50130331Sanholt	return (head)->next == head;
51130331Sanholt}
52130331Sanholt
53130331Sanholtstatic __inline__ void
54130331Sanholtlist_add_tail(struct list_head *entry, struct list_head *head) {
55130331Sanholt	(entry)->prev = (head)->prev;
56130331Sanholt	(entry)->next = head;
57130331Sanholt	(head)->prev->next = entry;
58130331Sanholt	(head)->prev = entry;
59130331Sanholt}
60130331Sanholt
61130331Sanholtstatic __inline__ void
62130331Sanholtlist_del(struct list_head *entry) {
63130331Sanholt	(entry)->next->prev = (entry)->prev;
64130331Sanholt	(entry)->prev->next = (entry)->next;
65130331Sanholt}
66130331Sanholt
67130331Sanholt#define list_for_each(entry, head)				\
68130331Sanholt    for (entry = (head)->next; entry != head; entry = (entry)->next)
69130331Sanholt
70189913Srnoland#define list_for_each_prev(entry, head) \
71189913Srnoland        for (entry = (head)->prev; entry != (head); \
72189913Srnoland                entry = entry->prev)
73189913Srnoland
74130331Sanholt#define list_for_each_safe(entry, temp, head)			\
75130331Sanholt    for (entry = (head)->next, temp = (entry)->next;		\
76183832Srnoland	entry != head; 						\
77183832Srnoland	entry = temp, temp = entry->next)
78130331Sanholt
79