9dbd745e6bdaf52ef1ccebae2dffd7c3b1308e82
[lttng-tools.git] / src / common / index-allocator.h
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>
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 struct lttng_index_allocator;
18
19 enum lttng_index_allocator_status {
20 LTTNG_INDEX_ALLOCATOR_STATUS_OK,
21 LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY,
22 LTTNG_INDEX_ALLOCATOR_STATUS_ERROR,
23 };
24
25 /*
26 * Create an index allocator of `index_count` slots.
27 */
28 struct lttng_index_allocator *lttng_index_allocator_create(
29 uint64_t index_count);
30
31 /*
32 * Get the number of indexes currently in use.
33 */
34 uint64_t lttng_index_allocator_get_index_count(
35 struct lttng_index_allocator *allocator);
36
37 /*
38 * Allocate (i.e. reserve) a slot.
39 */
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 */
48 enum lttng_index_allocator_status lttng_index_allocator_release(
49 struct lttng_index_allocator *allocator, uint64_t index);
50
51 /*
52 * Destroy an index allocator.
53 */
54 void lttng_index_allocator_destroy(struct lttng_index_allocator *allocator);
55
56 #ifdef __cplusplus
57 }
58 #endif
59
60 #endif /* _COMMON_INDEX_ALLOCATOR_H */
This page took 0.029152 seconds and 3 git commands to generate.