• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Paulo Alcantara <pcacjr@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 
20 #ifndef _RUNLIST_H_
21 #define _RUNLIST_H_
22 
23 struct runlist_element {
24     uint64_t vcn;
25     int64_t lcn;
26     uint64_t len;
27 };
28 
29 struct runlist {
30     struct runlist_element run;
31     struct runlist *next;
32 };
33 
34 static struct runlist *tail;
35 
runlist_is_empty(struct runlist * rlist)36 static inline bool runlist_is_empty(struct runlist *rlist)
37 {
38     return !rlist;
39 }
40 
runlist_alloc(void)41 static inline struct runlist *runlist_alloc(void)
42 {
43     struct runlist *rlist;
44 
45     rlist = malloc(sizeof *rlist);
46     if (!rlist)
47         malloc_error("runlist structure");
48 
49     rlist->next = NULL;
50 
51     return rlist;
52 }
53 
runlist_append(struct runlist ** rlist,struct runlist_element * elem)54 static inline void runlist_append(struct runlist **rlist,
55                                 struct runlist_element *elem)
56 {
57     struct runlist *n = runlist_alloc();
58 
59     n->run = *elem;
60 
61     if (runlist_is_empty(*rlist)) {
62         *rlist = n;
63         tail = n;
64     } else {
65         tail->next = n;
66         tail = n;
67     }
68 }
69 
runlist_remove(struct runlist ** rlist)70 static inline struct runlist *runlist_remove(struct runlist **rlist)
71 {
72     struct runlist *ret;
73 
74     if (runlist_is_empty(*rlist))
75         return NULL;
76 
77     ret = *rlist;
78     *rlist = ret->next;
79 
80     return ret;
81 }
82 
83 #endif /* _RUNLIST_H_ */
84