1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * klist.h - Some generic list helpers, extending struct list_head a bit.
5 * Implementations are found in lib/klist.c
7 * Copyright (C) 2005 Patrick Mochel
10 #ifndef _LINUX_KLIST_H
11 #define _LINUX_KLIST_H
13 #include <linux/spinlock.h>
14 #include <linux/kref.h>
15 #include <linux/list.h>
20 struct list_head k_list
;
21 void (*get
)(struct klist_node
*);
22 void (*put
)(struct klist_node
*);
23 } __attribute__ ((aligned (sizeof(void *))));
25 #define KLIST_INIT(_name, _get, _put) \
26 { .k_lock = __SPIN_LOCK_UNLOCKED(_name.k_lock), \
27 .k_list = LIST_HEAD_INIT(_name.k_list), \
31 #define DEFINE_KLIST(_name, _get, _put) \
32 struct klist _name = KLIST_INIT(_name, _get, _put)
34 extern void klist_init(struct klist
*k
, void (*get
)(struct klist_node
*),
35 void (*put
)(struct klist_node
*));
38 void *n_klist
; /* never access directly */
39 struct list_head n_node
;
43 extern void klist_add_tail(struct klist_node
*n
, struct klist
*k
);
44 extern void klist_add_head(struct klist_node
*n
, struct klist
*k
);
45 extern void klist_add_behind(struct klist_node
*n
, struct klist_node
*pos
);
46 extern void klist_add_before(struct klist_node
*n
, struct klist_node
*pos
);
48 extern void klist_del(struct klist_node
*n
);
49 extern void klist_remove(struct klist_node
*n
);
51 extern int klist_node_attached(struct klist_node
*n
);
55 struct klist
*i_klist
;
56 struct klist_node
*i_cur
;
60 extern void klist_iter_init(struct klist
*k
, struct klist_iter
*i
);
61 extern void klist_iter_init_node(struct klist
*k
, struct klist_iter
*i
,
62 struct klist_node
*n
);
63 extern void klist_iter_exit(struct klist_iter
*i
);
64 extern struct klist_node
*klist_prev(struct klist_iter
*i
);
65 extern struct klist_node
*klist_next(struct klist_iter
*i
);