Adds hexdump to a parlib header
[akaros.git] / user / parlib / include / bitmask.h
index 668ef19..b3d9d0b 100644 (file)
@@ -1,7 +1,9 @@
 #ifndef PARLIB_BITMASK_H
 #define PARLIB_BITMASK_H
 
-#include <arch/bitmask.h>
+#include <parlib/arch/bitmask.h>
+
+__BEGIN_DECLS
 
 static inline bool BITMASK_IS_SET_IN_RANGE(uint8_t* m, size_t beg, size_t end)
 {
@@ -36,17 +38,24 @@ static inline void CLR_BITMASK_RANGE(uint8_t* m, size_t beg, size_t end)
 }
 
 /* Runs *work on every bit in the bitmask, passing *work the value of the bit
- * that is set.  Optionally clears the bit from the bitmask */
-static void BITMASK_FOREACH_SET(uint8_t *name, unsigned int size,
-                                void (*work)(unsigned int bit), bool clear)
-{
-       for (int i = 0; i < size; i++) {
-               bool present = GET_BITMASK_BIT(name, i);
-               if (present && clear)
-                       CLR_BITMASK_BIT_ATOMIC(name, i);
-               if (present)
-                       work(i);
-       }
-}
+ * that is set.  Optionally clears the bit from the bitmask. 
+ *
+ * We need this to be a macro, so that the calling code doesn't need the
+ * address for work_fn.  This matters for code that has nested functions that
+ * use local variables, since taking the address of work_fn will force the
+ * compiler to put the function on the stack and incur icache coherency
+ * overheads. */
+#define BITMASK_FOREACH_SET(name, size, work_fn, clear)                        \
+{                                                                              \
+       for (int i = 0; i < (size); i++) {                                         \
+               bool present = GET_BITMASK_BIT((name), i);                             \
+               if (present && (clear))                                                \
+                       CLR_BITMASK_BIT_ATOMIC((name), i);                                 \
+               if (present)                                                           \
+                       (work_fn)(i);                                                      \
+       }                                                                          \
+}                                                                              
+                                                                               
+__END_DECLS
 
 #endif /* PARLIB_BITMASK_H */