summaryrefslogtreecommitdiff
path: root/libqueue/queue/sl.h
blob: 168107ac9f6b38c3a94f6cfa76614efca60aaacd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* vim: set ts=4 sw=4 ai:
 * sl.h -- singly linked list implementation derived from NetBSD's queue.h
 */

#ifndef SL_H
#define SL_H

struct sle {
	void *data;
	struct sle *next;
};

struct slh {
	struct sle *first;
};

#define sl_first(hd) ((hd)->first)
#define sl_next(e) ((e)->next)
#define sl_empty(hd) (((hd)->first) == NULL)
#define sl_init(hd) ((hd)->first = NULL)

#define sl_foreach(var,head) \
	for ((var) = ((head)->first); \
		(var) != NULL; \
		(var) = ((var)->next))

#define sl_foreach_safe(var,head,vnext) \
	for ((var) = ((head)->first); \
		(var) != NULL && ((vnext) = sl_next((var)), 1); \
		(var) = (vnext))

struct slh *sl_new(void);
struct sle *sl_elem_new(void *);
void sl_insert_after(struct sle *, struct sle *);
void sl_insert_head(struct slh *, struct sle *);
void sl_remove_after(struct sle *);
void sl_remove_head(struct slh *);
void sl_remove(struct slh *, struct sle *);
void sl_cleanup(struct slh *, void (*)(void *));
struct sle *sl_find_from_data(struct slh *, const void *, int (*)(const void *, const void *));

#endif/*!SL_H*/