~ubuntu-branches/ubuntu/oneiric/ratpoison/oneiric

« back to all changes in this revision

Viewing changes to src/linkedlist.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Walther
  • Date: 2005-05-05 16:46:52 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050505164652-0flkldl87xzrlmus
Tags: 1.3.0-7
Applied Luca Capello's patch for GDM support.  Closes: #307779

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "linkedlist.h"
 
2
 
 
3
void
 
4
prefetch(const void *x)
 
5
{;}
 
6
 
 
7
/*
 
8
 * Insert a new entry between two known consecutive entries. 
 
9
 *
 
10
 * This is only for internal list manipulation where we know
 
11
 * the prev/next entries already!
 
12
 */
 
13
void
 
14
__list_add(struct list_head *new,
 
15
           struct list_head *prev,
 
16
           struct list_head *next)
 
17
{
 
18
  next->prev = new;
 
19
  new->next = next;
 
20
  new->prev = prev;
 
21
  prev->next = new;
 
22
}
 
23
 
 
24
/**
 
25
 * list_add - add a new entry
 
26
 * @new: new entry to be added
 
27
 * @head: list head to add it after
 
28
 *
 
29
 * Insert a new entry after the specified head.
 
30
 * This is good for implementing stacks.
 
31
 */
 
32
void
 
33
list_add(struct list_head *new, struct list_head *head)
 
34
{
 
35
  __list_add(new, head, head->next);
 
36
}
 
37
 
 
38
/**
 
39
 * list_add_tail - add a new entry
 
40
 * @new: new entry to be added
 
41
 * @head: list head to add it before
 
42
 *
 
43
 * Insert a new entry before the specified head.
 
44
 * This is useful for implementing queues.
 
45
 */
 
46
void
 
47
list_add_tail(struct list_head *new, struct list_head *head)
 
48
{
 
49
  __list_add(new, head->prev, head);
 
50
}
 
51
 
 
52
/*
 
53
 * Delete a list entry by making the prev/next entries
 
54
 * point to each other.
 
55
 *
 
56
 * This is only for internal list manipulation where we know
 
57
 * the prev/next entries already!
 
58
 */
 
59
void
 
60
__list_del(struct list_head * prev, struct list_head * next)
 
61
{
 
62
  next->prev = prev;
 
63
  prev->next = next;
 
64
}
 
65
 
 
66
/**
 
67
 * list_del - deletes entry from list.
 
68
 * @entry: the element to delete from the list.
 
69
 * Note: list_empty on entry does not return true after this, the entry is
 
70
 * in an undefined state.
 
71
 */
 
72
void
 
73
list_del(struct list_head *entry)
 
74
{
 
75
  __list_del(entry->prev, entry->next);
 
76
}
 
77
 
 
78
/**
 
79
 * list_del_init - deletes entry from list and reinitialize it.
 
80
 * @entry: the element to delete from the list.
 
81
 */
 
82
void
 
83
list_del_init(struct list_head *entry)
 
84
{
 
85
  __list_del(entry->prev, entry->next);
 
86
  INIT_LIST_HEAD(entry); 
 
87
}
 
88
 
 
89
/**
 
90
 * list_move - delete from one list and add as another's head
 
91
 * @list: the entry to move
 
92
 * @head: the head that will precede our entry
 
93
 */
 
94
void
 
95
list_move(struct list_head *list, struct list_head *head)
 
96
{
 
97
  __list_del(list->prev, list->next);
 
98
  list_add(list, head);
 
99
}
 
100
 
 
101
/**
 
102
 * list_move_tail - delete from one list and add as another's tail
 
103
 * @list: the entry to move
 
104
 * @head: the head that will follow our entry
 
105
 */
 
106
void
 
107
list_move_tail(struct list_head *list,
 
108
               struct list_head *head)
 
109
{
 
110
  __list_del(list->prev, list->next);
 
111
  list_add_tail(list, head);
 
112
}
 
113
 
 
114
/**
 
115
 * list_empty - tests whether a list is empty
 
116
 * @head: the list to test.
 
117
 */
 
118
int
 
119
list_empty(struct list_head *head)
 
120
{
 
121
  return head->next == head;
 
122
}
 
123
 
 
124
void
 
125
__list_splice(struct list_head *list,
 
126
              struct list_head *head)
 
127
{
 
128
  struct list_head *first = list->next;
 
129
  struct list_head *last = list->prev;
 
130
  struct list_head *at = head->next;
 
131
 
 
132
  first->prev = head;
 
133
  head->next = first;
 
134
 
 
135
  last->next = at;
 
136
  at->prev = last;
 
137
}
 
138
 
 
139
/**
 
140
 * list_splice - join two lists
 
141
 * @list: the new list to add.
 
142
 * @head: the place to add it in the first list.
 
143
 */
 
144
void
 
145
list_splice(struct list_head *list, struct list_head *head)
 
146
{
 
147
  if (!list_empty(list))
 
148
    __list_splice(list, head);
 
149
}
 
150
 
 
151
/**
 
152
 * list_splice_init - join two lists and reinitialise the emptied list.
 
153
 * @list: the new list to add.
 
154
 * @head: the place to add it in the first list.
 
155
 *
 
156
 * The list at @list is reinitialised
 
157
 */
 
158
void
 
159
list_splice_init(struct list_head *list,
 
160
                 struct list_head *head)
 
161
{
 
162
  if (!list_empty(list)) {
 
163
    __list_splice(list, head);
 
164
    INIT_LIST_HEAD(list);
 
165
  }
 
166
}