lib: compile liblttng-ctl as C++
[lttng-tools.git] / src / common / index-allocator.h
CommitLineData
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
15extern "C" {
16#endif
17
246611b0
FD
18struct lttng_index_allocator;
19
20enum 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 29LTTNG_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 35LTTNG_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 41LTTNG_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 49LTTNG_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 55LTTNG_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 */
This page took 0.026758 seconds and 4 git commands to generate.