1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-22 17:35:59 +03:00
lvm2/libdm/datastruct/list.h

73 lines
1.3 KiB
C
Raw Normal View History

2001-10-31 15:47:01 +03:00
/*
* Copyright (C) 2001 Sistina Software
*
* This file is released under the LGPL.
*/
2001-10-01 19:14:39 +04:00
#ifndef _LVM_LIST_H
#define _LVM_LIST_H
2001-10-31 15:47:01 +03:00
#include <assert.h>
2001-10-31 15:47:01 +03:00
struct list {
struct list *n, *p;
};
2001-10-31 15:47:01 +03:00
static inline void list_init(struct list *head) {
head->n = head->p = head;
}
2001-10-31 15:47:01 +03:00
static inline void list_add(struct list *head, struct list *elem) {
assert(head->n);
2001-10-31 15:47:01 +03:00
elem->n = head;
elem->p = head->p;
2001-10-31 15:47:01 +03:00
head->p->n = elem;
head->p = elem;
}
2001-10-31 15:47:01 +03:00
static inline void list_add_h(struct list *head, struct list *elem) {
assert(head->n);
2001-10-31 15:47:01 +03:00
elem->n = head->n;
elem->p = head;
2001-10-31 15:47:01 +03:00
head->n->p = elem;
head->n = elem;
}
2001-10-31 15:47:01 +03:00
static inline void list_del(struct list *elem) {
elem->n->p = elem->p;
elem->p->n = elem->n;
}
2001-10-31 15:47:01 +03:00
static inline int list_empty(struct list *head) {
return head->n == head;
}
2001-10-31 15:47:01 +03:00
#define list_iterate(v, head) \
for (v = (head)->n; v != head; v = v->n)
#define list_iterate_safe(v, t, head) \
for (v = (head)->n, t = v->n; v != head; v = t, t = v->n)
static inline int list_size(struct list *head) {
int s = 0;
struct list *v;
list_iterate(v, head)
s++;
return s;
}
2001-10-31 15:47:01 +03:00
#define list_item(v, t) \
2001-11-15 17:14:03 +03:00
((t *)((uintptr_t)(v) - (uintptr_t)&((t *) 0)->list))
/* Given a known element in a known structure, locate the struct list */
#define list_head(v, t, e) \
2001-11-15 17:14:03 +03:00
(((t *)((uintptr_t)(v) - (uintptr_t)&((t *) 0)->e))->list)
#endif