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 | ||
11 | #include <inttypes.h> | |
4bd69c5f | 12 | #include <lttng/lttng-export.h> |
246611b0 | 13 | |
7966af57 SM |
14 | #ifdef __cplusplus |
15 | extern "C" { | |
16 | #endif | |
17 | ||
246611b0 FD |
18 | struct lttng_index_allocator; |
19 | ||
20 | enum lttng_index_allocator_status { | |
21 | LTTNG_INDEX_ALLOCATOR_STATUS_OK, | |
22 | LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY, | |
23 | LTTNG_INDEX_ALLOCATOR_STATUS_ERROR, | |
24 | }; | |
25 | ||
26 | /* | |
27 | * Create an index allocator of `index_count` slots. | |
28 | */ | |
4bd69c5f | 29 | LTTNG_EXPORT struct lttng_index_allocator *lttng_index_allocator_create( |
246611b0 FD |
30 | uint64_t index_count); |
31 | ||
32 | /* | |
33 | * Get the number of indexes currently in use. | |
34 | */ | |
4bd69c5f | 35 | LTTNG_EXPORT uint64_t lttng_index_allocator_get_index_count( |
246611b0 FD |
36 | struct lttng_index_allocator *allocator); |
37 | ||
38 | /* | |
39 | * Allocate (i.e. reserve) a slot. | |
40 | */ | |
4bd69c5f | 41 | LTTNG_EXPORT enum lttng_index_allocator_status lttng_index_allocator_alloc( |
246611b0 FD |
42 | struct lttng_index_allocator *allocator, |
43 | uint64_t *index); | |
44 | ||
45 | /* | |
46 | * Release a slot by index. The slot will be re-used by the index allocator | |
47 | * in future 'alloc' calls. | |
48 | */ | |
4bd69c5f | 49 | LTTNG_EXPORT enum lttng_index_allocator_status lttng_index_allocator_release( |
246611b0 FD |
50 | struct lttng_index_allocator *allocator, uint64_t index); |
51 | ||
52 | /* | |
53 | * Destroy an index allocator. | |
54 | */ | |
4bd69c5f | 55 | LTTNG_EXPORT void lttng_index_allocator_destroy(struct lttng_index_allocator *allocator); |
246611b0 | 56 | |
7966af57 SM |
57 | #ifdef __cplusplus |
58 | } | |
59 | #endif | |
60 | ||
246611b0 | 61 | #endif /* _COMMON_INDEX_ALLOCATOR_H */ |