DRM update to git snapshot from 2008-01-04.
[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  * $DragonFly: src/sys/dev/drm/drm_linux_list.h,v 1.1 2008/04/05 18:12:29 hasso Exp $
31  */
32
33 struct list_head {
34         struct list_head *next, *prev;
35 };
36
37 /* Cheat, assume the list_head is at the start of the struct */
38 #define list_entry(entry, type, member) (type *)(entry)
39
40 static __inline__ void
41 INIT_LIST_HEAD(struct list_head *head) {
42         (head)->next = head;
43         (head)->prev = head;
44 }
45
46 static __inline__ int
47 list_empty(struct list_head *head) {
48         return (head)->next == head;
49 }
50
51 static __inline__ void
52 list_add_tail(struct list_head *entry, struct list_head *head) {
53         (entry)->prev = (head)->prev;
54         (entry)->next = head;
55         (head)->prev->next = entry;
56         (head)->prev = entry;
57 }
58
59 static __inline__ void
60 list_del(struct list_head *entry) {
61         (entry)->next->prev = (entry)->prev;
62         (entry)->prev->next = (entry)->next;
63 }
64
65 #define list_for_each(entry, head)                              \
66     for (entry = (head)->next; entry != head; entry = (entry)->next)
67
68 #define list_for_each_safe(entry, temp, head)                   \
69     for (entry = (head)->next, temp = (entry)->next;            \
70         temp != head;                                           \
71         entry = temp, temp = temp->next)
72