]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/klist.h
Add a new sysfs_streq() string comparison function
[mirror_ubuntu-bionic-kernel.git] / include / linux / klist.h
CommitLineData
9a19fea4
PM
1/*
2 * klist.h - Some generic list helpers, extending struct list_head a bit.
3 *
4 * Implementations are found in lib/klist.c
5 *
6 *
7 * Copyright (C) 2005 Patrick Mochel
8 *
9 * This file is rleased under the GPL v2.
10 */
11
d856f1e3
JB
12#ifndef _LINUX_KLIST_H
13#define _LINUX_KLIST_H
14
9a19fea4
PM
15#include <linux/spinlock.h>
16#include <linux/completion.h>
17#include <linux/kref.h>
18#include <linux/list.h>
19
34bb61f9 20struct klist_node;
9a19fea4
PM
21struct klist {
22 spinlock_t k_lock;
23 struct list_head k_list;
34bb61f9
JB
24 void (*get)(struct klist_node *);
25 void (*put)(struct klist_node *);
9a19fea4
PM
26};
27
1da43e4a
TH
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, }
33
34#define DEFINE_KLIST(_name, _get, _put) \
35 struct klist _name = KLIST_INIT(_name, _get, _put)
9a19fea4 36
c3bb7fad 37extern void klist_init(struct klist *k, void (*get)(struct klist_node *),
34bb61f9 38 void (*put)(struct klist_node *));
9a19fea4
PM
39
40struct klist_node {
c3bb7fad 41 struct klist *n_klist;
9a19fea4
PM
42 struct list_head n_node;
43 struct kref n_ref;
44 struct completion n_removed;
45};
46
c3bb7fad
GKH
47extern void klist_add_tail(struct klist_node *n, struct klist *k);
48extern void klist_add_head(struct klist_node *n, struct klist *k);
93dd4001
TH
49extern void klist_add_after(struct klist_node *n, struct klist_node *pos);
50extern void klist_add_before(struct klist_node *n, struct klist_node *pos);
9a19fea4 51
c3bb7fad
GKH
52extern void klist_del(struct klist_node *n);
53extern void klist_remove(struct klist_node *n);
9a19fea4 54
c3bb7fad 55extern int klist_node_attached(struct klist_node *n);
8b0c250b 56
9a19fea4
PM
57
58struct klist_iter {
c3bb7fad
GKH
59 struct klist *i_klist;
60 struct list_head *i_head;
61 struct klist_node *i_cur;
9a19fea4
PM
62};
63
64
c3bb7fad
GKH
65extern void klist_iter_init(struct klist *k, struct klist_iter *i);
66extern void klist_iter_init_node(struct klist *k, struct klist_iter *i,
67 struct klist_node *n);
68extern void klist_iter_exit(struct klist_iter *i);
69extern struct klist_node *klist_next(struct klist_iter *i);
9a19fea4 70
d856f1e3 71#endif