mochel@digitalimplant.org | 9a19fea | 2005-03-21 11:45:16 -0800 | [diff] [blame] | 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 | |
James Bottomley | d856f1e | 2005-08-19 09:14:01 -0400 | [diff] [blame^] | 12 | #ifndef _LINUX_KLIST_H |
| 13 | #define _LINUX_KLIST_H |
| 14 | |
mochel@digitalimplant.org | 9a19fea | 2005-03-21 11:45:16 -0800 | [diff] [blame] | 15 | #include <linux/spinlock.h> |
| 16 | #include <linux/completion.h> |
| 17 | #include <linux/kref.h> |
| 18 | #include <linux/list.h> |
| 19 | |
| 20 | |
| 21 | struct klist { |
| 22 | spinlock_t k_lock; |
| 23 | struct list_head k_list; |
| 24 | }; |
| 25 | |
| 26 | |
| 27 | extern void klist_init(struct klist * k); |
| 28 | |
| 29 | |
| 30 | struct klist_node { |
| 31 | struct klist * n_klist; |
| 32 | struct list_head n_node; |
| 33 | struct kref n_ref; |
| 34 | struct completion n_removed; |
| 35 | }; |
| 36 | |
James Bottomley | d856f1e | 2005-08-19 09:14:01 -0400 | [diff] [blame^] | 37 | extern void klist_add_tail(struct klist_node * n, struct klist * k); |
| 38 | extern void klist_add_head(struct klist_node * n, struct klist * k); |
mochel@digitalimplant.org | 9a19fea | 2005-03-21 11:45:16 -0800 | [diff] [blame] | 39 | |
| 40 | extern void klist_del(struct klist_node * n); |
| 41 | extern void klist_remove(struct klist_node * n); |
| 42 | |
mochel@digitalimplant.org | 8b0c250 | 2005-03-24 12:58:57 -0800 | [diff] [blame] | 43 | extern int klist_node_attached(struct klist_node * n); |
| 44 | |
mochel@digitalimplant.org | 9a19fea | 2005-03-21 11:45:16 -0800 | [diff] [blame] | 45 | |
| 46 | struct klist_iter { |
| 47 | struct klist * i_klist; |
| 48 | struct list_head * i_head; |
| 49 | struct klist_node * i_cur; |
| 50 | }; |
| 51 | |
| 52 | |
| 53 | extern void klist_iter_init(struct klist * k, struct klist_iter * i); |
| 54 | extern void klist_iter_init_node(struct klist * k, struct klist_iter * i, |
| 55 | struct klist_node * n); |
| 56 | extern void klist_iter_exit(struct klist_iter * i); |
| 57 | extern struct klist_node * klist_next(struct klist_iter * i); |
| 58 | |
James Bottomley | d856f1e | 2005-08-19 09:14:01 -0400 | [diff] [blame^] | 59 | #endif |