X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Findex-allocator.cpp;h=c0bb8a1c4188d19f7e99cdc341a6b0e165df4117;hb=HEAD;hp=1f7b3e05208d3cfb6fa60785f4db7218f57f7588;hpb=64803277bbdbe0a943360d918298a48157d9da55;p=lttng-tools.git diff --git a/src/common/index-allocator.cpp b/src/common/index-allocator.cpp index 1f7b3e052..c0bb8a1c4 100644 --- a/src/common/index-allocator.cpp +++ b/src/common/index-allocator.cpp @@ -5,16 +5,14 @@ * */ -#include +#include "error.hpp" +#include "index-allocator.hpp" +#include "macros.hpp" +#include #include #include -#include "macros.hpp" -#include "error.hpp" - -#include "index-allocator.hpp" - struct lttng_index_allocator { struct cds_list_head unused_list; uint64_t size; @@ -22,15 +20,16 @@ struct lttng_index_allocator { uint64_t nb_allocated_indexes; }; +namespace { struct lttng_index { uint64_t index; struct cds_list_head head; }; +} /* namespace */ -struct lttng_index_allocator *lttng_index_allocator_create( - uint64_t index_count) +struct lttng_index_allocator *lttng_index_allocator_create(uint64_t index_count) { - struct lttng_index_allocator *allocator = NULL; + struct lttng_index_allocator *allocator = nullptr; allocator = zmalloc(); if (!allocator) { @@ -53,12 +52,10 @@ uint64_t lttng_index_allocator_get_index_count(struct lttng_index_allocator *all return allocator->nb_allocated_indexes; } -enum lttng_index_allocator_status lttng_index_allocator_alloc( - struct lttng_index_allocator *allocator, - uint64_t *allocated_index) +enum lttng_index_allocator_status +lttng_index_allocator_alloc(struct lttng_index_allocator *allocator, uint64_t *allocated_index) { - enum lttng_index_allocator_status status = - LTTNG_INDEX_ALLOCATOR_STATUS_OK; + enum lttng_index_allocator_status status = LTTNG_INDEX_ALLOCATOR_STATUS_OK; if (cds_list_empty(&allocator->unused_list)) { if (allocator->position >= allocator->size) { @@ -71,8 +68,7 @@ enum lttng_index_allocator_status lttng_index_allocator_alloc( } else { struct lttng_index *index; - index = cds_list_first_entry(&allocator->unused_list, - typeof(*index), head); + index = cds_list_first_entry(&allocator->unused_list, typeof(*index), head); cds_list_del(&index->head); *allocated_index = index->index; free(index); @@ -83,12 +79,11 @@ end: return status; } -enum lttng_index_allocator_status lttng_index_allocator_release( - struct lttng_index_allocator *allocator, uint64_t idx) +enum lttng_index_allocator_status +lttng_index_allocator_release(struct lttng_index_allocator *allocator, uint64_t idx) { - struct lttng_index *index = NULL; - enum lttng_index_allocator_status status = - LTTNG_INDEX_ALLOCATOR_STATUS_OK; + struct lttng_index *index = nullptr; + enum lttng_index_allocator_status status = LTTNG_INDEX_ALLOCATOR_STATUS_OK; LTTNG_ASSERT(idx < allocator->size); @@ -109,20 +104,18 @@ end: void lttng_index_allocator_destroy(struct lttng_index_allocator *allocator) { - struct lttng_index *index = NULL, *tmp_index = NULL; + struct lttng_index *index = nullptr, *tmp_index = nullptr; if (!allocator) { return; } if (lttng_index_allocator_get_index_count(allocator) > 0) { - WARN("Destroying index allocator with %" PRIu64 - " slot indexes still in use", - lttng_index_allocator_get_index_count(allocator)); + WARN("Destroying index allocator with %" PRIu64 " slot indexes still in use", + lttng_index_allocator_get_index_count(allocator)); } - cds_list_for_each_entry_safe(index, tmp_index, - &allocator->unused_list, head) { + cds_list_for_each_entry_safe (index, tmp_index, &allocator->unused_list, head) { cds_list_del(&index->head); free(index); }