1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - util.h *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2012 Mupen64plus development team *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
30 #include "osal/preproc.h"
33 struct list_head *prev;
34 struct list_head *next;
37 #define LIST_HEAD(list) \
38 struct list_head list = { &(list), &(list) }
40 static osal_inline void INIT_LIST_HEAD(struct list_head *head)
46 static osal_inline void list_add(struct list_head *new_item, struct list_head *head)
48 struct list_head *next = head->next;
50 next->prev = new_item;
51 new_item->next = next;
52 new_item->prev = head;
53 head->next = new_item;
56 static osal_inline void list_add_tail(struct list_head *new_item, struct list_head *head)
58 struct list_head *prev = head->prev;
60 prev->next = new_item;
61 new_item->next = head;
62 new_item->prev = prev;
63 head->prev = new_item;
66 static osal_inline void list_del(struct list_head *entry)
68 struct list_head *next = entry->next;
69 struct list_head *prev = entry->prev;
75 static osal_inline void list_del_init(struct list_head *entry)
78 INIT_LIST_HEAD(entry);
81 static osal_inline int list_empty(const struct list_head *head)
83 return (head->next == head);
88 #define container_of(ptr, type, member) ({ \
89 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
90 (type *)( (char *)__mptr - offsetof(type,member) );})
94 #define container_of(ptr, type, member) \
95 ((type *)((char *)(ptr) - offsetof(type, member)))
99 #define list_entry(ptr, type, member) container_of(ptr, type, member)
101 #define list_first_entry(ptr, type, member) \
102 list_entry((ptr)->next, type, member)
104 #define list_for_each(pos, head) \
105 for (pos = (head)->next; pos != (head); pos = pos->next)
107 #define list_for_each_entry(pos, head, type, member) \
108 for (pos = list_entry((head)->next, type, member); \
109 &pos->member != (head); \
110 pos = list_entry(pos->member.next, type, member))
112 #define list_for_each_safe(pos, safe, head) \
113 for (pos = (head)->next, safe = pos->next; pos != (head); \
114 pos = safe, safe = pos->next)
116 #define list_for_each_entry_safe(pos, safe, head, type, member) \
117 for (pos = list_entry((head)->next, type, member), \
118 safe = list_entry(pos->member.next, type, member); \
119 &pos->member != (head); \
121 safe = list_entry(safe->member.next, type, member))