38 #include <linux/export.h>
39 #include <linux/sched.h>
45 #define KNODE_DEAD 1LU
46 #define KNODE_KLIST_MASK ~KNODE_DEAD
50 return (
struct klist *)
54 static bool knode_dead(
struct klist_node *knode)
66 static void knode_kill(
struct klist_node *knode)
88 INIT_LIST_HEAD(&k->
k_list);
95 static void add_head(
struct klist *k,
struct klist_node *
n)
102 static void add_tail(
struct klist *k,
struct klist_node *
n)
109 static void klist_node_init(
struct klist *k,
struct klist_node *
n)
111 INIT_LIST_HEAD(&n->
n_node);
112 kref_init(&n->
n_ref);
113 knode_set_klist(n, k);
125 klist_node_init(k, n);
137 klist_node_init(k, n);
149 struct klist *k = knode_klist(pos);
151 klist_node_init(k, n);
165 struct klist *k = knode_klist(pos);
167 klist_node_init(k, n);
184 static void klist_release(
struct kref *
kref)
191 spin_lock(&klist_remove_lock);
193 if (waiter->
node != n)
201 spin_unlock(&klist_remove_lock);
202 knode_set_klist(n,
NULL);
205 static int klist_dec_and_del(
struct klist_node *n)
207 return kref_put(&n->
n_ref, klist_release);
210 static void klist_put(
struct klist_node *n,
bool kill)
212 struct klist *k = knode_klist(n);
218 if (!klist_dec_and_del(n))
246 spin_lock(&klist_remove_lock);
247 list_add(&waiter.
list, &klist_remove_waiters);
248 spin_unlock(&klist_remove_lock);
315 klist_put(i->
i_cur,
false);
340 spin_lock(&i->
i_klist->k_lock);
343 next = to_klist_node(
last->n_node.next);
344 if (!klist_dec_and_del(
last))
350 while (
next != to_klist_node(&i->
i_klist->k_list)) {
352 kref_get(&
next->n_ref);
356 next = to_klist_node(
next->n_node.next);
359 spin_unlock(&i->
i_klist->k_lock);