]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/slists.c
2 * BIRD Library -- Safe Linked Lists
4 * (c) 1998 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
9 #define _BIRD_SLISTS_C_
11 #include "nest/bird.h"
12 #include "lib/slists.h"
15 s_merge(snode
*from
, snode
*to
)
19 if (!(f
= from
->readers
))
21 if (!(g
= to
->readers
))
25 f
->prev
= (siterator
*) to
;
51 * No node found. We have to walk the iterator list backwards
52 * to find where are we linked.
59 f
= i
->prev
; /* Maybe the snode itself */
71 s_put(siterator
*i
, snode
*n
)
80 i
->prev
= (siterator
*) n
;
85 s_add_tail(slist
*l
, snode
*n
)
89 n
->next
= (snode
*) &l
->null
;
97 s_add_head(slist
*l
, snode
*n
)
102 n
->prev
= (snode
*) &l
->head
;
109 s_insert_node(snode
*n
, snode
*after
)
111 snode
*z
= after
->next
;
132 s_init_list(slist
*l
)
134 l
->head
= (snode
*) &l
->null
;
136 l
->tail
= (snode
*) &l
->head
;
137 l
->tail_readers
= NULL
;
141 s_add_tail_list(slist
*to
, slist
*l
)
149 q
->next
= (snode
*) &to
->null
;
151 s_merge((snode
*) &l
->null
, (snode
*) &to
->null
);
156 #include "lib/resource.h"
159 void dump(char *c
, slist
*a
)
164 for(x
=SHEAD(*a
); x
; x
=x
->next
)
169 for(i
=x
->readers
; i
; i
=i
->next
)
174 printf(" [%p:%p]", i
, i
->node
);
189 x
= xmalloc(sizeof(*x
));
191 x
= xmalloc(sizeof(*x
));
193 x
= xmalloc(sizeof(*x
));
202 printf("Got %p\n", x
);
218 s_rem_node(a
.head
->next
);
219 dump("6 (deletion)", &a
);
221 s_put(&i
, s_get(&i
)->next
);
222 dump("6 (relink)", &a
);
224 x
= xmalloc(sizeof(*x
));
226 dump("7 (second list)", &b
);
228 s_add_tail_list(&b
, &a
);
229 dump("8 (after merge)", &b
);