2 * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #ifndef _COMMON_INDEX_ALLOCATOR_H
9 #define _COMMON_INDEX_ALLOCATOR_H
13 struct lttng_index_allocator
;
15 enum lttng_index_allocator_status
{
16 LTTNG_INDEX_ALLOCATOR_STATUS_OK
,
17 LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY
,
18 LTTNG_INDEX_ALLOCATOR_STATUS_ERROR
,
22 * Create an index allocator of `index_count` slots.
24 struct lttng_index_allocator
*lttng_index_allocator_create(
25 uint64_t index_count
);
28 * Get the number of indexes currently in use.
30 uint64_t lttng_index_allocator_get_index_count(
31 struct lttng_index_allocator
*allocator
);
34 * Allocate (i.e. reserve) a slot.
36 enum lttng_index_allocator_status
lttng_index_allocator_alloc(
37 struct lttng_index_allocator
*allocator
,
41 * Release a slot by index. The slot will be re-used by the index allocator
42 * in future 'alloc' calls.
44 enum lttng_index_allocator_status
lttng_index_allocator_release(
45 struct lttng_index_allocator
*allocator
, uint64_t index
);
48 * Destroy an index allocator.
50 void lttng_index_allocator_destroy(struct lttng_index_allocator
*allocator
);
52 #endif /* _COMMON_INDEX_ALLOCATOR_H */