Commit | Line | Data |
---|---|---|
246611b0 FD |
1 | /* |
2 | * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: GPL-2.0-only | |
5 | * | |
6 | */ | |
7 | ||
8 | #ifndef _COMMON_INDEX_ALLOCATOR_H | |
9 | #define _COMMON_INDEX_ALLOCATOR_H | |
10 | ||
4bd69c5f | 11 | #include <lttng/lttng-export.h> |
246611b0 | 12 | |
28f23191 JG |
13 | #include <inttypes.h> |
14 | ||
246611b0 FD |
15 | struct lttng_index_allocator; |
16 | ||
17 | enum lttng_index_allocator_status { | |
18 | LTTNG_INDEX_ALLOCATOR_STATUS_OK, | |
19 | LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY, | |
20 | LTTNG_INDEX_ALLOCATOR_STATUS_ERROR, | |
21 | }; | |
22 | ||
23 | /* | |
24 | * Create an index allocator of `index_count` slots. | |
25 | */ | |
28f23191 JG |
26 | extern "C" LTTNG_EXPORT struct lttng_index_allocator * |
27 | lttng_index_allocator_create(uint64_t index_count); | |
246611b0 FD |
28 | |
29 | /* | |
30 | * Get the number of indexes currently in use. | |
31 | */ | |
28f23191 JG |
32 | extern "C" LTTNG_EXPORT uint64_t |
33 | lttng_index_allocator_get_index_count(struct lttng_index_allocator *allocator); | |
246611b0 FD |
34 | |
35 | /* | |
36 | * Allocate (i.e. reserve) a slot. | |
37 | */ | |
28f23191 JG |
38 | extern "C" LTTNG_EXPORT enum lttng_index_allocator_status |
39 | lttng_index_allocator_alloc(struct lttng_index_allocator *allocator, uint64_t *index); | |
246611b0 FD |
40 | |
41 | /* | |
42 | * Release a slot by index. The slot will be re-used by the index allocator | |
43 | * in future 'alloc' calls. | |
44 | */ | |
28f23191 JG |
45 | extern "C" LTTNG_EXPORT enum lttng_index_allocator_status |
46 | lttng_index_allocator_release(struct lttng_index_allocator *allocator, uint64_t index); | |
246611b0 FD |
47 | |
48 | /* | |
49 | * Destroy an index allocator. | |
50 | */ | |
28f23191 | 51 | extern "C" LTTNG_EXPORT void lttng_index_allocator_destroy(struct lttng_index_allocator *allocator); |
7966af57 | 52 | |
246611b0 | 53 | #endif /* _COMMON_INDEX_ALLOCATOR_H */ |