X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Findex-allocator.hpp;fp=src%2Fcommon%2Findex-allocator.hpp;h=ee7c2ec758dd5dd707780b9a42ae5d3c0d4fab6c;hb=7532fa3bd22e403958f46cd35c824f490d93292d;hp=0000000000000000000000000000000000000000;hpb=985aea182b618c85c51651f224abedfe367c75ee;p=deliverable%2Flttng-tools.git diff --git a/src/common/index-allocator.hpp b/src/common/index-allocator.hpp new file mode 100644 index 000000000..ee7c2ec75 --- /dev/null +++ b/src/common/index-allocator.hpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 Francis Deslauriers + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef _COMMON_INDEX_ALLOCATOR_H +#define _COMMON_INDEX_ALLOCATOR_H + +#include +#include + +struct lttng_index_allocator; + +enum lttng_index_allocator_status { + LTTNG_INDEX_ALLOCATOR_STATUS_OK, + LTTNG_INDEX_ALLOCATOR_STATUS_EMPTY, + LTTNG_INDEX_ALLOCATOR_STATUS_ERROR, +}; + +/* + * Create an index allocator of `index_count` slots. + */ +extern "C" LTTNG_EXPORT +struct lttng_index_allocator *lttng_index_allocator_create( + uint64_t index_count); + +/* + * Get the number of indexes currently in use. + */ +extern "C" LTTNG_EXPORT +uint64_t lttng_index_allocator_get_index_count( + struct lttng_index_allocator *allocator); + +/* + * Allocate (i.e. reserve) a slot. + */ +extern "C" LTTNG_EXPORT +enum lttng_index_allocator_status lttng_index_allocator_alloc( + struct lttng_index_allocator *allocator, + uint64_t *index); + +/* + * Release a slot by index. The slot will be re-used by the index allocator + * in future 'alloc' calls. + */ +extern "C" LTTNG_EXPORT +enum lttng_index_allocator_status lttng_index_allocator_release( + struct lttng_index_allocator *allocator, uint64_t index); + +/* + * Destroy an index allocator. + */ +extern "C" LTTNG_EXPORT +void lttng_index_allocator_destroy(struct lttng_index_allocator *allocator); + +#endif /* _COMMON_INDEX_ALLOCATOR_H */