util/idalloc: add util_idalloc_reserve

Can be used to mark an id as used (if it was reclaimed without using
util_idalloc_alloc).

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6600>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2020-09-07 14:47:47 +02:00
parent 87ef970ee6
commit e808d38299
2 changed files with 11 additions and 0 deletions

View file

@ -94,3 +94,11 @@ util_idalloc_free(struct util_idalloc *buf, unsigned id)
assert(id < buf->num_elements);
buf->data[id / 32] &= ~(1 << (id % 32));
}
void
util_idalloc_reserve(struct util_idalloc *buf, unsigned id)
{
assert(id < buf->num_elements);
assert((buf->data[id / 32] & (1u << (id % 32))) == 0);
buf->data[id / 32] |= 1u << (id % 32);
}

View file

@ -55,6 +55,9 @@ util_idalloc_alloc(struct util_idalloc *buf);
void
util_idalloc_free(struct util_idalloc *buf, unsigned id);
void
util_idalloc_reserve(struct util_idalloc *buf, unsigned id);
#ifdef __cplusplus
}
#endif