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
11 #include <lttng/lttng-export.h>
15 struct lttng_index_allocator;
17 enum lttng_index_allocator_status {
18 LTTNG_INDEX_ALLOCATOR_STATUS_OK,
19 LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY,
20 LTTNG_INDEX_ALLOCATOR_STATUS_ERROR,
24 * Create an index allocator of `index_count` slots.
26 extern "C" LTTNG_EXPORT struct lttng_index_allocator *
27 lttng_index_allocator_create(uint64_t index_count);
30 * Get the number of indexes currently in use.
32 extern "C" LTTNG_EXPORT uint64_t
33 lttng_index_allocator_get_index_count(struct lttng_index_allocator *allocator);
36 * Allocate (i.e. reserve) a slot.
38 extern "C" LTTNG_EXPORT enum lttng_index_allocator_status
39 lttng_index_allocator_alloc(struct lttng_index_allocator *allocator, uint64_t *index);
42 * Release a slot by index. The slot will be re-used by the index allocator
43 * in future 'alloc' calls.
45 extern "C" LTTNG_EXPORT enum lttng_index_allocator_status
46 lttng_index_allocator_release(struct lttng_index_allocator *allocator, uint64_t index);
49 * Destroy an index allocator.
51 extern "C" LTTNG_EXPORT void lttng_index_allocator_destroy(struct lttng_index_allocator *allocator);
53 #endif /* _COMMON_INDEX_ALLOCATOR_H */