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>
14 struct lttng_index_allocator;
16 enum lttng_index_allocator_status {
17 LTTNG_INDEX_ALLOCATOR_STATUS_OK,
18 LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY,
19 LTTNG_INDEX_ALLOCATOR_STATUS_ERROR,
23 * Create an index allocator of `index_count` slots.
25 extern "C" LTTNG_EXPORT
26 struct lttng_index_allocator *lttng_index_allocator_create(
27 uint64_t index_count);
30 * Get the number of indexes currently in use.
32 extern "C" LTTNG_EXPORT
33 uint64_t lttng_index_allocator_get_index_count(
34 struct lttng_index_allocator *allocator);
37 * Allocate (i.e. reserve) a slot.
39 extern "C" LTTNG_EXPORT
40 enum lttng_index_allocator_status lttng_index_allocator_alloc(
41 struct lttng_index_allocator *allocator,
45 * Release a slot by index. The slot will be re-used by the index allocator
46 * in future 'alloc' calls.
48 extern "C" LTTNG_EXPORT
49 enum lttng_index_allocator_status lttng_index_allocator_release(
50 struct lttng_index_allocator *allocator, uint64_t index);
53 * Destroy an index allocator.
55 extern "C" LTTNG_EXPORT
56 void lttng_index_allocator_destroy(struct lttng_index_allocator *allocator);
58 #endif /* _COMMON_INDEX_ALLOCATOR_H */