nlm: Ensure callback code also checks that the files match
[GitHub/mt8127/android_kernel_alcatel_ttab.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 15#include <linux/spinlock.h>
9a19fea4
PM
16#include <linux/kref.h>
17#include <linux/list.h>
18
34bb61f9 19struct klist_node;
9a19fea4
PM
20struct klist {
21 spinlock_t k_lock;
22 struct list_head k_list;
34bb61f9
JB
23 void (*get)(struct klist_node *);
24 void (*put)(struct klist_node *);
795abaf1 25} __attribute__ ((aligned (sizeof(void *))));
9a19fea4 26
1da43e4a
TH
27#define KLIST_INIT(_name, _get, _put) \
28 { .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \
29 .k_list = LIST_HEAD_INIT(_name.k_list), \
30 .get = _get, \
31 .put = _put, }
32
33#define DEFINE_KLIST(_name, _get, _put) \
34 struct klist _name = KLIST_INIT(_name, _get, _put)
9a19fea4 35
c3bb7fad 36extern void klist_init(struct klist *k, void (*get)(struct klist_node *),
34bb61f9 37 void (*put)(struct klist_node *));
9a19fea4
PM
38
39struct klist_node {
a1ed5b0c 40 void *n_klist; /* never access directly */
9a19fea4
PM
41 struct list_head n_node;
42 struct kref n_ref;
9a19fea4
PM
43};
44
c3bb7fad
GKH
45extern void klist_add_tail(struct klist_node *n, struct klist *k);
46extern void klist_add_head(struct klist_node *n, struct klist *k);
93dd4001
TH
47extern void klist_add_after(struct klist_node *n, struct klist_node *pos);
48extern void klist_add_before(struct klist_node *n, struct klist_node *pos);
9a19fea4 49
c3bb7fad
GKH
50extern void klist_del(struct klist_node *n);
51extern void klist_remove(struct klist_node *n);
9a19fea4 52
c3bb7fad 53extern int klist_node_attached(struct klist_node *n);
8b0c250b 54
9a19fea4
PM
55
56struct klist_iter {
c3bb7fad 57 struct klist *i_klist;
c3bb7fad 58 struct klist_node *i_cur;
9a19fea4
PM
59};
60
61
c3bb7fad
GKH
62extern void klist_iter_init(struct klist *k, struct klist_iter *i);
63extern void klist_iter_init_node(struct klist *k, struct klist_iter *i,
64 struct klist_node *n);
65extern void klist_iter_exit(struct klist_iter *i);
66extern struct klist_node *klist_next(struct klist_iter *i);
9a19fea4 67
d856f1e3 68#endif