diff options
author | kaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk> | 2005-12-29 18:39:50 +0100 |
---|---|---|
committer | kaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk> | 2005-12-29 18:39:50 +0100 |
commit | fc41b5c1fdbe11dd608c8f8cf1880e30c1233668 (patch) | |
tree | 3722294a828cb987fe3242e6f38166b7ca374bca /xen/common/rangeset.c | |
parent | 9e1d90563dfc38b901a354b0e752408f076b6d68 (diff) | |
download | xen-fc41b5c1fdbe11dd608c8f8cf1880e30c1233668.tar.gz xen-fc41b5c1fdbe11dd608c8f8cf1880e30c1233668.tar.bz2 xen-fc41b5c1fdbe11dd608c8f8cf1880e30c1233668.zip |
Extend the range abstraction by adding an internal
insert_range() helper function. Pretty printer uses
the internal abstractions rather than accessing the
linked list directly.
Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'xen/common/rangeset.c')
-rw-r--r-- | xen/common/rangeset.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/xen/common/rangeset.c b/xen/common/rangeset.c index 35bdb3f656..228986c33a 100644 --- a/xen/common/rangeset.c +++ b/xen/common/rangeset.c @@ -32,6 +32,10 @@ struct rangeset { unsigned int flags; }; +/***************************** + * Private range functions hide the underlying linked-list implemnetation. + */ + /* Find highest range lower than or containing s. NULL if no such range. */ static struct range *find_range( struct rangeset *r, unsigned long s) @@ -66,6 +70,13 @@ static struct range *next_range( return list_entry(x->list.next, struct range, list); } +/* Insert range y after range x in r. Insert as first range if x is NULL. */ +static void insert_range( + struct rangeset *r, struct range *x, struct range *y) +{ + list_add(&y->list, (x != NULL) ? &x->list : &r->range_list); +} + /* Remove a range from its list and free it. */ static void destroy_range( struct range *x) @@ -74,6 +85,10 @@ static void destroy_range( xfree(x); } +/***************************** + * Core public functions + */ + int rangeset_add_range( struct rangeset *r, unsigned long s, unsigned long e) { @@ -99,10 +114,9 @@ int rangeset_add_range( x->s = s; x->e = e; - list_add(&x->list, (y != NULL) ? &y->list : &r->range_list); + insert_range(r, y, x); } - - if ( x->e < e ) + else if ( x->e < e ) x->e = e; } else @@ -165,10 +179,12 @@ int rangeset_remove_range( rc = -ENOMEM; goto out; } + y->s = e + 1; y->e = x->e; x->e = s - 1; - list_add(&y->list, &x->list); + + insert_range(r, x, y); } else if ( (x->s == s) && (x->e <= e) ) destroy_range(x); @@ -317,6 +333,10 @@ void rangeset_domain_destroy( } } +/***************************** + * Pretty-printing functions + */ + static void print_limit(struct rangeset *r, unsigned long s) { printk((r->flags & RANGESETF_prettyprint_hex) ? "%lx" : "%lu", s); @@ -332,7 +352,7 @@ void rangeset_printk( printk("%10s {", r->name); - list_for_each_entry ( x, &r->range_list, list ) + for ( x = first_range(r); x != NULL; x = next_range(r, x) ) { if ( nr_printed++ ) printk(","); |