Whamcloud - gitweb
LU-3494 libcfs: Add relocation function to libcfs heap
[fs/lustre-release.git] / libcfs / libcfs / heap.c
index 3a4f168..ed87fa7 100644 (file)
@@ -41,7 +41,7 @@
 do {                                                                   \
        if ((h)->cbh_flags & CBH_FLAG_ATOMIC_GROW)                      \
                LIBCFS_CPT_ALLOC_GFP((ptr), h->cbh_cptab, h->cbh_cptid, \
-                                    CBH_NOB, CFS_ALLOC_ATOMIC);        \
+                                    CBH_NOB, GFP_ATOMIC);              \
        else                                                            \
                LIBCFS_CPT_ALLOC((ptr), h->cbh_cptab, h->cbh_cptid,     \
                                 CBH_NOB);                              \
@@ -463,8 +463,7 @@ cfs_binheap_remove(cfs_binheap_t *h, cfs_binheap_node_t *e)
 
        last->chn_index = cur_idx;
        *cur_ptr = last;
-       if (!cfs_binheap_bubble(h, *cur_ptr))
-               cfs_binheap_sink(h, *cur_ptr);
+       cfs_binheap_relocate(h, *cur_ptr);
 
        e->chn_index = CBH_POISON;
        if (h->cbh_ops->hop_exit)
@@ -472,4 +471,19 @@ cfs_binheap_remove(cfs_binheap_t *h, cfs_binheap_node_t *e)
 }
 EXPORT_SYMBOL(cfs_binheap_remove);
 
+/**
+ * Relocate a node in the binary heap.
+ * Should be called whenever a node's values
+ * which affects its ranking are changed.
+ *
+ * \param[in] h The heap
+ * \param[in] e The node
+ */
+void
+cfs_binheap_relocate(cfs_binheap_t *h, cfs_binheap_node_t *e)
+{
+       if (!cfs_binheap_bubble(h, e))
+               cfs_binheap_sink(h, e);
+}
+EXPORT_SYMBOL(cfs_binheap_relocate);
 /** @} heap */