Blame view
include/linux/klist.h
1.82 KB
9a19fea43
|
1 2 3 4 5 6 7 8 9 10 |
/* * klist.h - Some generic list helpers, extending struct list_head a bit. * * Implementations are found in lib/klist.c * * * Copyright (C) 2005 Patrick Mochel * * This file is rleased under the GPL v2. */ |
d856f1e33
|
11 12 |
#ifndef _LINUX_KLIST_H #define _LINUX_KLIST_H |
9a19fea43
|
13 |
#include <linux/spinlock.h> |
9a19fea43
|
14 15 |
#include <linux/kref.h> #include <linux/list.h> |
34bb61f9d
|
16 |
struct klist_node; |
9a19fea43
|
17 18 19 |
struct klist { spinlock_t k_lock; struct list_head k_list; |
34bb61f9d
|
20 21 |
void (*get)(struct klist_node *); void (*put)(struct klist_node *); |
795abaf1e
|
22 |
} __attribute__ ((aligned (sizeof(void *)))); |
9a19fea43
|
23 |
|
1da43e4a9
|
24 25 26 27 28 29 30 31 |
#define KLIST_INIT(_name, _get, _put) \ { .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \ .k_list = LIST_HEAD_INIT(_name.k_list), \ .get = _get, \ .put = _put, } #define DEFINE_KLIST(_name, _get, _put) \ struct klist _name = KLIST_INIT(_name, _get, _put) |
9a19fea43
|
32 |
|
c3bb7fada
|
33 |
extern void klist_init(struct klist *k, void (*get)(struct klist_node *), |
34bb61f9d
|
34 |
void (*put)(struct klist_node *)); |
9a19fea43
|
35 36 |
struct klist_node { |
a1ed5b0cf
|
37 |
void *n_klist; /* never access directly */ |
9a19fea43
|
38 39 |
struct list_head n_node; struct kref n_ref; |
9a19fea43
|
40 |
}; |
c3bb7fada
|
41 42 |
extern void klist_add_tail(struct klist_node *n, struct klist *k); extern void klist_add_head(struct klist_node *n, struct klist *k); |
93dd40013
|
43 44 |
extern void klist_add_after(struct klist_node *n, struct klist_node *pos); extern void klist_add_before(struct klist_node *n, struct klist_node *pos); |
9a19fea43
|
45 |
|
c3bb7fada
|
46 47 |
extern void klist_del(struct klist_node *n); extern void klist_remove(struct klist_node *n); |
9a19fea43
|
48 |
|
c3bb7fada
|
49 |
extern int klist_node_attached(struct klist_node *n); |
8b0c250be
|
50 |
|
9a19fea43
|
51 52 |
struct klist_iter { |
c3bb7fada
|
53 |
struct klist *i_klist; |
c3bb7fada
|
54 |
struct klist_node *i_cur; |
9a19fea43
|
55 |
}; |
c3bb7fada
|
56 57 58 59 60 |
extern void klist_iter_init(struct klist *k, struct klist_iter *i); extern void klist_iter_init_node(struct klist *k, struct klist_iter *i, struct klist_node *n); extern void klist_iter_exit(struct klist_iter *i); extern struct klist_node *klist_next(struct klist_iter *i); |
9a19fea43
|
61 |
|
d856f1e33
|
62 |
#endif |