Buddy pools: Add check for available allocations

parent edea7f6b
......@@ -2823,6 +2823,8 @@ t_pool_fill(struct buddy_reqs *reqs, const void *priv)
// defines t_pool_s_get()
BUDDY_POOL_GET_FUNC(t_pool_s, static)
// defines t_pool_s_avail()
BUDDY_POOL_AVAIL_FUNC(t_pool_s, static)
/*
* get allocations from a pool and return them
......@@ -2847,6 +2849,7 @@ t_pool(void)
for (u = 0; u < 42; u++) {
reqs = t_pool_s_get(pool, NULL);
AN(t_pool_s_avail(pool));
alloc = buddy_get_next_ptr_page(reqs);
assert(alloc.ptr > 0);
do {
......
......@@ -626,6 +626,23 @@ name ## _get(struct name *poolp, const void *priv) \
WRONG("Expected second return() to be hit"); \
}
// return available allocations, does not block
#define BUDDY_POOL_AVAIL_FUNC(name, decl) \
decl unsigned \
name ## _avail(struct name *poolp) \
{ \
struct buddy_reqs *reqs; \
unsigned u, avail = 0; \
\
CHECK_OBJ_NOTNULL(poolp, BUDDY_POOL_MAGIC); \
for (u = 0; u < 2; u++) { \
reqs = &((poolp)->reqs[u].reqs); \
CHECK_OBJ_NOTNULL(reqs, BUDDY_REQS_MAGIC); \
avail += buddy_reqs_next_ready(reqs); \
} \
return (avail); \
}
#define BUDDY_POOL_INIT(poolp, b, f, p) do { \
INIT_OBJ(poolp, BUDDY_POOL_MAGIC); \
poolp->fill = f; \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment