2012-02-06 21:09:42 +01:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2011 Felix Fietkau <nbd@openwrt.org>
|
|
|
|
* Copyright (c) 2010 Isilon Systems, Inc.
|
|
|
|
* Copyright (c) 2010 iX Systems, Inc.
|
|
|
|
* Copyright (c) 2010 Panasas, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice unmodified, this list of conditions, and the following
|
|
|
|
* disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#ifndef _LINUX_LIST_H_
|
|
|
|
#define _LINUX_LIST_H_
|
2010-10-13 21:17:51 +02:00
|
|
|
|
|
|
|
#include <stddef.h>
|
2012-02-06 21:09:42 +01:00
|
|
|
#include <stdbool.h>
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
#define prefetch(x)
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
#ifndef container_of
|
2013-03-18 05:54:44 +01:00
|
|
|
#define container_of(ptr, type, member) \
|
|
|
|
({ \
|
2018-04-07 15:21:25 +02:00
|
|
|
const __typeof__(((type *) NULL)->member) *__mptr = (ptr); \
|
2013-03-18 05:54:44 +01:00
|
|
|
(type *) ((char *) __mptr - offsetof(type, member)); \
|
|
|
|
})
|
2012-02-06 21:09:42 +01:00
|
|
|
#endif
|
2010-10-13 21:17:51 +02:00
|
|
|
|
|
|
|
struct list_head {
|
2012-02-06 21:09:42 +01:00
|
|
|
struct list_head *next;
|
|
|
|
struct list_head *prev;
|
2010-10-13 21:17:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
2012-10-04 16:11:04 +02:00
|
|
|
#undef LIST_HEAD
|
2012-02-06 21:09:42 +01:00
|
|
|
#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
INIT_LIST_HEAD(struct list_head *list)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
list->next = list->prev = list;
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline bool
|
|
|
|
list_empty(const struct list_head *head)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
return (head->next == head);
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline bool
|
|
|
|
list_is_first(const struct list_head *list,
|
|
|
|
const struct list_head *head)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
return list->prev == head;
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline bool
|
|
|
|
list_is_last(const struct list_head *list,
|
|
|
|
const struct list_head *head)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
return list->next == head;
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
_list_del(struct list_head *entry)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
entry->next->prev = entry->prev;
|
|
|
|
entry->prev->next = entry->next;
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_del(struct list_head *entry)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
_list_del(entry);
|
|
|
|
entry->next = entry->prev = NULL;
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
_list_add(struct list_head *_new, struct list_head *prev,
|
|
|
|
struct list_head *next)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
next->prev = _new;
|
|
|
|
_new->next = next;
|
|
|
|
_new->prev = prev;
|
|
|
|
prev->next = _new;
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_del_init(struct list_head *entry)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
_list_del(entry);
|
2010-10-13 21:17:51 +02:00
|
|
|
INIT_LIST_HEAD(entry);
|
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
#define list_entry(ptr, type, field) container_of(ptr, type, field)
|
|
|
|
#define list_first_entry(ptr, type, field) list_entry((ptr)->next, type, field)
|
|
|
|
#define list_last_entry(ptr, type, field) list_entry((ptr)->prev, type, field)
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
#define list_for_each(p, head) \
|
|
|
|
for (p = (head)->next; p != (head); p = p->next)
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
#define list_for_each_safe(p, n, head) \
|
|
|
|
for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next)
|
|
|
|
|
|
|
|
#define list_for_each_entry(p, h, field) \
|
2018-04-07 15:21:25 +02:00
|
|
|
for (p = list_first_entry(h, __typeof__(*p), field); &p->field != (h); \
|
|
|
|
p = list_entry(p->field.next, __typeof__(*p), field))
|
2012-02-06 21:09:42 +01:00
|
|
|
|
|
|
|
#define list_for_each_entry_safe(p, n, h, field) \
|
2018-04-07 15:21:25 +02:00
|
|
|
for (p = list_first_entry(h, __typeof__(*p), field), \
|
|
|
|
n = list_entry(p->field.next, __typeof__(*p), field); &p->field != (h);\
|
|
|
|
p = n, n = list_entry(n->field.next, __typeof__(*n), field))
|
2012-02-06 21:09:42 +01:00
|
|
|
|
|
|
|
#define list_for_each_entry_reverse(p, h, field) \
|
2018-04-07 15:21:25 +02:00
|
|
|
for (p = list_last_entry(h, __typeof__(*p), field); &p->field != (h); \
|
|
|
|
p = list_entry(p->field.prev, __typeof__(*p), field))
|
2012-02-06 21:09:42 +01:00
|
|
|
|
|
|
|
#define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = p->prev)
|
|
|
|
#define list_for_each_prev_safe(p, n, h) for (p = (h)->prev, n = p->prev; p != (h); p = n, n = p->prev)
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
list_add(struct list_head *_new, struct list_head *head)
|
2010-12-28 23:59:06 +01:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
_list_add(_new, head, head->next);
|
2010-12-28 23:59:06 +01:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_add_tail(struct list_head *_new, struct list_head *head)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
_list_add(_new, head->prev, head);
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_move(struct list_head *list, struct list_head *head)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
_list_del(list);
|
|
|
|
list_add(list, head);
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_move_tail(struct list_head *entry, struct list_head *head)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
_list_del(entry);
|
|
|
|
list_add_tail(entry, head);
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
_list_splice(const struct list_head *list, struct list_head *prev,
|
|
|
|
struct list_head *next)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
struct list_head *first;
|
|
|
|
struct list_head *last;
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
if (list_empty(list))
|
|
|
|
return;
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
first = list->next;
|
|
|
|
last = list->prev;
|
|
|
|
first->prev = prev;
|
|
|
|
prev->next = first;
|
|
|
|
last->next = next;
|
|
|
|
next->prev = last;
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_splice(const struct list_head *list, struct list_head *head)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
_list_splice(list, head, head->next);
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_splice_tail(struct list_head *list, struct list_head *head)
|
2010-10-13 21:17:51 +02:00
|
|
|
{
|
2012-02-06 21:09:42 +01:00
|
|
|
_list_splice(list, head->prev, head);
|
2010-10-13 21:17:51 +02:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_splice_init(struct list_head *list, struct list_head *head)
|
|
|
|
{
|
|
|
|
_list_splice(list, head, head->next);
|
|
|
|
INIT_LIST_HEAD(list);
|
|
|
|
}
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
static inline void
|
|
|
|
list_splice_tail_init(struct list_head *list, struct list_head *head)
|
|
|
|
{
|
|
|
|
_list_splice(list, head->prev, head);
|
|
|
|
INIT_LIST_HEAD(list);
|
|
|
|
}
|
2010-10-13 21:17:51 +02:00
|
|
|
|
2012-02-06 21:09:42 +01:00
|
|
|
#endif /* _LINUX_LIST_H_ */
|