[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] libxl: provide libxl_bitmap_{and,or}
Added functions to create the logical 'and' and logical 'or' of two input bitmaps. Cleaned up spacing and comments. Removed accidentally committed libxl_u_disk* files. Signed-off-by: Linda Jacobson <lindaj@xxxxxxxx> --- tools/libxl/libxl_utils.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_utils.h | 6 ++++++ 2 files changed, 61 insertions(+) diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 9053b27..fb8830a 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -691,6 +691,61 @@ void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit) bitmap->map[bit / 8] &= ~(1 << (bit & 7)); } +int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map, + libxl_bitmap *map1, libxl_bitmap *map2) +{ + uint32_t size; + int rc; + int bit; + + GC_INIT(ctx); + /* if bitmaps aren't same size, the bitmap of their logical + or should be the size of the larger bit map + */ + size = max(map1->size, map2->size); + rc = libxl_bitmap_alloc(ctx, or_map, size); + if (rc) + goto out; + + for (bit = 0; bit < (size * 8); bit++) { + if (libxl_bitmap_test(map1, bit)) + libxl_bitmap_set(or_map, bit); + else if (libxl_bitmap_test(map2, bit)) + libxl_bitmap_set(or_map, bit); + } + +out: + GC_FREE; + return rc; +} + +int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map, + libxl_bitmap *map1, libxl_bitmap *map2) +{ + uint32_t size; + int rc; + int bit; + + GC_INIT(ctx); + /* if bitmaps aren't same size, logical and should + be the size of the smaller bit map + */ + size = min(map1->size, map2->size); + rc = libxl_bitmap_alloc(ctx, and_map, size); + if (rc) + goto out; + + for (bit = 0; bit < (size * 8); bit++) { + if (libxl_bitmap_test (map1, bit) && + libxl_bitmap_test (map2, bit) ) + libxl_bitmap_set (and_map, bit); + } + +out: + GC_FREE; + return rc; + } + int libxl_bitmap_count_set(const libxl_bitmap *bitmap) { int i, nr_set_bits = 0; diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h index 68b5580..0b6480d 100644 --- a/tools/libxl/libxl_utils.h +++ b/tools/libxl/libxl_utils.h @@ -91,6 +91,12 @@ void libxl_bitmap_set(libxl_bitmap *bitmap, int bit); void libxl_bitmap_reset(libxl_bitmap *bitmap, int bit); int libxl_bitmap_count_set(const libxl_bitmap *bitmap); char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *bitmap); +/* or, and and xor functions for two bitmaps + */ +int libxl_bitmap_or(libxl_ctx *ctx, libxl_bitmap *or_map, + libxl_bitmap *map1, libxl_bitmap *map2); +int libxl_bitmap_and(libxl_ctx *ctx, libxl_bitmap *and_map, + libxl_bitmap *map1, libxl_bitmap *map2); static inline void libxl_bitmap_set_any(libxl_bitmap *bitmap) { memset(bitmap->map, -1, bitmap->size); -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |