iwl3945 : Simplify iwl3945_pci_probe
[linux-2.6/mini2440.git] / include / linux / klist.h
blob8ea98db223e567db691efb28fe1153d60d2f6d78
1 /*
2 * klist.h - Some generic list helpers, extending struct list_head a bit.
4 * Implementations are found in lib/klist.c
7 * Copyright (C) 2005 Patrick Mochel
9 * This file is rleased under the GPL v2.
12 #ifndef _LINUX_KLIST_H
13 #define _LINUX_KLIST_H
15 #include <linux/spinlock.h>
16 #include <linux/completion.h>
17 #include <linux/kref.h>
18 #include <linux/list.h>
20 struct klist_node;
21 struct klist {
22 spinlock_t k_lock;
23 struct list_head k_list;
24 void (*get)(struct klist_node *);
25 void (*put)(struct klist_node *);
28 #define KLIST_INIT(_name, _get, _put) \
29 { .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \
30 .k_list = LIST_HEAD_INIT(_name.k_list), \
31 .get = _get, \
32 .put = _put, }
34 #define DEFINE_KLIST(_name, _get, _put) \
35 struct klist _name = KLIST_INIT(_name, _get, _put)
37 extern void klist_init(struct klist *k, void (*get)(struct klist_node *),
38 void (*put)(struct klist_node *));
40 struct klist_node {
41 void *n_klist; /* never access directly */
42 struct list_head n_node;
43 struct kref n_ref;
44 struct completion n_removed;
47 extern void klist_add_tail(struct klist_node *n, struct klist *k);
48 extern void klist_add_head(struct klist_node *n, struct klist *k);
49 extern void klist_add_after(struct klist_node *n, struct klist_node *pos);
50 extern void klist_add_before(struct klist_node *n, struct klist_node *pos);
52 extern void klist_del(struct klist_node *n);
53 extern void klist_remove(struct klist_node *n);
55 extern int klist_node_attached(struct klist_node *n);
58 struct klist_iter {
59 struct klist *i_klist;
60 struct klist_node *i_cur;
64 extern void klist_iter_init(struct klist *k, struct klist_iter *i);
65 extern void klist_iter_init_node(struct klist *k, struct klist_iter *i,
66 struct klist_node *n);
67 extern void klist_iter_exit(struct klist_iter *i);
68 extern struct klist_node *klist_next(struct klist_iter *i);
70 #endif