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