[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH V2 1/3] Add function to find and set next available bit



Add function to find the next available bit in the bitmap and set it.

Signed-off-by: Stefan Berger <stefanb linux vnet ibm com>

---
 src/libvirt_private.syms |    1 +
 src/util/virbitmap.c     |   34 ++++++++++++++++++++++++++++++++++
 src/util/virbitmap.h     |    3 +++
 3 files changed, 38 insertions(+)

Index: libvirt/src/util/virbitmap.c
===================================================================
--- libvirt.orig/src/util/virbitmap.c
+++ libvirt/src/util/virbitmap.c
@@ -642,3 +642,37 @@ virBitmapCountBits(virBitmapPtr bitmap)
 
     return ret;
 }
+
+
+/**
+ * virBitmapSetNextBit:
+ * @bitmap: the bitmap
+ * @pos: the position after which to search for a clear bit and set it
+ *
+ * search the first clear bit after position @pos in bitmap @bitmap
+ * and set it. @pos can be -1 to search for the first set bit.
+ * Position starts at 0.
+ *
+ * returns the position of the set bit, or -1 if no bit could be set
+ */
+size_t
+virBitmapSetNextBit(virBitmapPtr bitmap, ssize_t pos)
+{
+    if (pos < 0)
+        pos = -1;
+
+    pos++;
+
+    if (pos >= bitmap->max_bit)
+        return -1;
+
+    while (pos < bitmap->max_bit) {
+        if (!virBitmapIsSet(bitmap, pos)) {
+            ignore_value(virBitmapSetBit(bitmap, pos));
+            return pos;
+        }
+        pos++;
+    }
+
+    return -1;
+}
Index: libvirt/src/util/virbitmap.h
===================================================================
--- libvirt.orig/src/util/virbitmap.h
+++ libvirt/src/util/virbitmap.h
@@ -106,4 +106,7 @@ ssize_t virBitmapNextSetBit(virBitmapPtr
 size_t virBitmapCountBits(virBitmapPtr bitmap)
     ATTRIBUTE_NONNULL(1);
 
+size_t virBitmapSetNextBit(virBitmapPtr bitmap, ssize_t pos)
+    ATTRIBUTE_NONNULL(1);
+
 #endif
Index: libvirt/src/libvirt_private.syms
===================================================================
--- libvirt.orig/src/libvirt_private.syms
+++ libvirt/src/libvirt_private.syms
@@ -22,6 +22,7 @@ virBitmapNextSetBit;
 virBitmapParse;
 virBitmapSetAll;
 virBitmapSetBit;
+virBitmapSetNextBit;
 virBitmapSize;
 virBitmapString;
 virBitmapToData;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]