Commit | Line | Data |
---|---|---|
63eba147 JA |
1 | /* |
2 | * blktrace output analysis: generate a timeline & gather statistics | |
3 | * | |
4 | * Copyright (C) 2006 Alan D. Brunelle <Alan.Brunelle@hp.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | #include "globals.h" | |
22 | ||
23 | struct cy_list { | |
24 | struct list_head head; | |
25 | struct list_head list; | |
26 | }; | |
27 | ||
28 | struct cy_list *pending_cys; | |
29 | ||
30 | static inline void __rem_cy(struct io_list *iolp) | |
31 | { | |
32 | io_unlink(&iolp->iop); | |
33 | if (--iolp->cy_users == 0) { | |
34 | LIST_DEL(&iolp->head); | |
35 | free(iolp); | |
36 | } | |
37 | } | |
38 | ||
39 | void rem_c(struct io *iop) | |
40 | { | |
41 | struct list_head *p, *q; | |
42 | struct io_list *iolp; | |
43 | ||
44 | ASSERT(iop->type == IOP_C); | |
45 | ||
46 | list_for_each_safe(p, q, &pending_cys->list) { | |
47 | iolp = list_entry(p, struct io_list, head); | |
48 | ||
49 | if (iolp->iop == iop) { | |
50 | __rem_cy(iolp); | |
51 | break; | |
52 | } | |
53 | } | |
54 | } | |
55 | ||
56 | void run_cy_list(struct list_head *list) | |
57 | { | |
58 | struct list_head *p, *q; | |
59 | struct io_list *iolp; | |
60 | ||
61 | list_for_each_safe(p, q, list) { | |
62 | iolp = list_entry(p, struct io_list, head); | |
63 | traverse(iolp->iop); | |
64 | __rem_cy(iolp); | |
65 | } | |
66 | } | |
67 | ||
68 | void add_cy(struct io *iop) | |
69 | { | |
70 | struct io_list *iolp = malloc(sizeof(*iolp)); | |
71 | ||
72 | ASSERT(iop->type == IOP_C || iop->type == IOP_Y); | |
73 | ||
74 | iolp->cy_users = 1; | |
75 | io_link(&iolp->iop, iop); | |
76 | ||
77 | list_add_tail(&iolp->head, &pending_cys->list); | |
78 | if (pending_xs == 0) | |
79 | run_cy_list(&pending_cys->list); | |
80 | } | |
81 | ||
82 | void cy_init(void) | |
83 | { | |
84 | pending_cys = zmalloc(sizeof(*pending_cys)); | |
85 | INIT_LIST_HEAD(&pending_cys->list); | |
86 | } | |
87 | ||
88 | void cy_shutdown(void) | |
89 | { | |
90 | ASSERT(list_empty(&pending_cys->list)); | |
91 | free(pending_cys); | |
92 | } |