~psusi/ubuntu/precise/dmraid/fix-gpt

« back to all changes in this revision

Viewing changes to 1.0.0.rc14/include/dmraid/list.h

  • Committer: Bazaar Package Importer
  • Author(s): Giuseppe Iuculano, 6af052c
  • Date: 2009-03-25 22:34:59 UTC
  • mfrom: (2.1.9 sid)
  • mto: (2.4.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: james.westby@ubuntu.com-20090325223459-y54f0rmxem7htn6r
Tags: 1.0.0.rc15-6
[6af052c] Remove 15_isw_incorrect_status_fix.patch, it causes a
segfault. (Closes: #521104)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2004,2005  Heinz Mauelshagen, Red Hat GmbH.
3
 
 *                          All rights reserved.
4
 
 *
5
 
 * See file LICENSE at the top of this source tree for license information.
6
 
 */
7
 
 
8
 
#ifndef _LIST_H
9
 
#define _LIST_H
10
 
 
11
 
/*
12
 
 * Double-linked list definitons and macros.
13
 
 */
14
 
 
15
 
struct list_head {
16
 
        struct list_head *next;
17
 
        struct list_head *prev;
18
 
};
19
 
 
20
 
#define INIT_LIST_HEAD(a)       do { (a)->next = (a)->prev = a; } while(0)
21
 
 
22
 
#define LIST_HEAD(a)    struct list_head a = { .next = &a, .prev = &a }
23
 
 
24
 
#define list_empty(pos) ((pos)->next == pos)
25
 
 
26
 
static inline void __list_add(struct list_head *new,
27
 
                              struct list_head *prev,
28
 
                              struct list_head *next)
29
 
{
30
 
        next->prev = new;
31
 
        new->next = next;
32
 
        new->prev = prev;
33
 
        prev->next = new;
34
 
}
35
 
 
36
 
/* Add an element 'new' after position 'pos' to a list. */
37
 
#define list_add(new, pos)      __list_add(new, pos, (pos)->next)
38
 
 
39
 
/* Add an element 'new' before position 'pos' to a list. */
40
 
#define list_add_tail(new, pos) __list_add(new, (pos)->prev, pos)
41
 
 
42
 
/* Delete an element 'pos' from the list. */
43
 
#define list_del(pos) { \
44
 
        (pos)->next->prev = (pos)->prev; \
45
 
        (pos)->prev->next = (pos)->next; \
46
 
        (pos)->next = (pos)->prev = 0; \
47
 
}
48
 
 
49
 
#define list_del_init(pos) { \
50
 
        list_del(pos); \
51
 
        INIT_LIST_HEAD(pos); \
52
 
}
53
 
 
54
 
/* Pointer to a struct 'type' derived from 'pos' and list_head* 'member'. */
55
 
#define list_entry(pos, type, member) \
56
 
        ((type*) ((char*)pos - (unsigned long)(&((type*)0)->member)))
57
 
 
58
 
/* Walk a list. */
59
 
#define list_for_each(pos, head) \
60
 
        for (pos = (head)->next; pos != head; pos = pos->next)
61
 
 
62
 
/* Walk a list by entry. */
63
 
#define list_for_each_entry(entry, head, member) \
64
 
        for (entry = list_entry((head)->next, typeof(*entry), member); \
65
 
             &entry->member != (head); \
66
 
             entry = list_entry(entry->member.next, typeof(*entry), member))
67
 
 
68
 
/*
69
 
 * Walk a list using a temporary pointer,
70
 
 * so that elements can be deleted safely.
71
 
 */
72
 
#define list_for_each_safe(pos, n, head) \
73
 
        for (pos = (head)->next, n = pos->next; \
74
 
             pos != (head); \
75
 
             pos = n, n = pos->next)
76
 
 
77
 
#endif