Move all sources to 'src/'
[lttng-ust.git] / src / libcounter / counter-internal.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng Counters Internal Header
7 */
8
9 #ifndef _LTTNG_COUNTER_INTERNAL_H
10 #define _LTTNG_COUNTER_INTERNAL_H
11
12 #include <stdint.h>
13 #include <lttng/ust-config.h>
14 #include <urcu/compiler.h>
15 #include "counter-types.h"
16
17 static inline int lttng_counter_validate_indexes(
18 const struct lib_counter_config *config __attribute__((unused)),
19 struct lib_counter *counter,
20 const size_t *dimension_indexes)
21 {
22 size_t nr_dimensions = counter->nr_dimensions, i;
23
24 for (i = 0; i < nr_dimensions; i++) {
25 if (caa_unlikely(dimension_indexes[i] >= counter->dimensions[i].max_nr_elem))
26 return -EOVERFLOW;
27 }
28 return 0;
29 }
30
31
32 static inline size_t lttng_counter_get_index(
33 const struct lib_counter_config *config __attribute__((unused)),
34 struct lib_counter *counter,
35 const size_t *dimension_indexes)
36 {
37 size_t nr_dimensions = counter->nr_dimensions, i;
38 size_t index = 0;
39
40 for (i = 0; i < nr_dimensions; i++) {
41 struct lib_counter_dimension *dimension = &counter->dimensions[i];
42 const size_t *dimension_index = &dimension_indexes[i];
43
44 index += *dimension_index * dimension->stride;
45 }
46 return index;
47 }
48
49 #endif /* _LTTNG_COUNTER_INTERNAL_H */
This page took 0.030319 seconds and 4 git commands to generate.