session: add support for memfd segments
[vpp.git] / src / vppinfra / bihash_template.c
index 704d165..3f25b02 100644 (file)
@@ -35,11 +35,20 @@ void BV (clib_bihash_init)
   vec_validate_aligned (h->buckets, nbuckets - 1, CLIB_CACHE_LINE_BYTES);
   h->writer_lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES,
                                           CLIB_CACHE_LINE_BYTES);
+  h->writer_lock[0] = 0;
 
   for (i = 0; i < nbuckets; i++)
     BV (clib_bihash_reset_cache) (h->buckets + i);
 
   clib_mem_set_heap (oldheap);
+
+  h->fmt_fn = NULL;
+}
+
+void BV (clib_bihash_set_kvp_format_fn) (BVT (clib_bihash) * h,
+                                        format_function_t * fmt_fn)
+{
+  h->fmt_fn = fmt_fn;
 }
 
 void BV (clib_bihash_free) (BVT (clib_bihash) * h)
@@ -509,10 +518,11 @@ u8 *BV (format_bihash_lru) (u8 * s, va_list * args)
 
   for (i = 0; i < BIHASH_KVP_CACHE_SIZE; i++)
     s = format (s, "[%d] ", ((cache_lru >> (3 * i)) & 7));
+
+  return (s);
 #else
   return format (s, "cache not configured");
 #endif
-  return (s);
 }
 
 void
@@ -564,9 +574,18 @@ u8 *BV (format_bihash) (u8 * s, va_list * args)
                }
              if (verbose)
                {
-                 s = format (s, "    %d: %U\n",
-                             j * BIHASH_KVP_PER_PAGE + k,
-                             BV (format_bihash_kvp), &(v->kvp[k]));
+                 if (h->fmt_fn)
+                   {
+                     s = format (s, "    %d: %U\n",
+                                 j * BIHASH_KVP_PER_PAGE + k,
+                                 h->fmt_fn, &(v->kvp[k]));
+                   }
+                 else
+                   {
+                     s = format (s, "    %d: %U\n",
+                                 j * BIHASH_KVP_PER_PAGE + k,
+                                 BV (format_bihash_kvp), &(v->kvp[k]));
+                   }
                }
              active_elements++;
            }