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
12 #include <lttng/lttng-export.h>
18 struct lttng_index_allocator
;
20 enum lttng_index_allocator_status
{
21 LTTNG_INDEX_ALLOCATOR_STATUS_OK
,
22 LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY
,
23 LTTNG_INDEX_ALLOCATOR_STATUS_ERROR
,
27 * Create an index allocator of `index_count` slots.
29 LTTNG_EXPORT
struct lttng_index_allocator
*lttng_index_allocator_create(
30 uint64_t index_count
);
33 * Get the number of indexes currently in use.
35 LTTNG_EXPORT
uint64_t lttng_index_allocator_get_index_count(
36 struct lttng_index_allocator
*allocator
);
39 * Allocate (i.e. reserve) a slot.
41 LTTNG_EXPORT
enum lttng_index_allocator_status
lttng_index_allocator_alloc(
42 struct lttng_index_allocator
*allocator
,
46 * Release a slot by index. The slot will be re-used by the index allocator
47 * in future 'alloc' calls.
49 LTTNG_EXPORT
enum lttng_index_allocator_status
lttng_index_allocator_release(
50 struct lttng_index_allocator
*allocator
, uint64_t index
);
53 * Destroy an index allocator.
55 LTTNG_EXPORT
void lttng_index_allocator_destroy(struct lttng_index_allocator
*allocator
);
61 #endif /* _COMMON_INDEX_ALLOCATOR_H */