diff options
author | Oliver Smith <osmith@sysmocom.de> | 2021-03-26 11:34:34 +0100 |
---|---|---|
committer | Oliver Smith <osmith@sysmocom.de> | 2021-04-06 11:27:34 +0200 |
commit | d3490bc442ec68d300bbb96b419d25c25de0f01e (patch) | |
tree | 0fb8dc37368ffa545a5a62e9d36512a6532e99d4 /src | |
parent | 8bd63b667e64ac8b91b33b7845967ddaf2628c64 (diff) |
stat_item: make next_id argument name consistent
Let osmo_stat_item_get_next, osmo_stat_item_discard,
osmo_stat_item_discard_all consistently refer to their next_id arg as
such (and not idx or next_idx). It refers to an ID (item->values[i].id),
not an index (item->values[i]), and it is always the next one, never the
current one.
Do the same change for _index/_idx variables in stats.c, which are used
as arguments to these functions. Replace rd_ with next_id_ in
stats_test.c, too.
Related: OS#5088
Change-Id: I5dd566b08dff7174d1790f49abd2d6ac020e120e
Diffstat (limited to 'src')
-rw-r--r-- | src/stat_item.c | 40 | ||||
-rw-r--r-- | src/stats.c | 12 |
2 files changed, 26 insertions, 26 deletions
diff --git a/src/stat_item.c b/src/stat_item.c index ba364640..31298fd7 100644 --- a/src/stat_item.c +++ b/src/stat_item.c @@ -195,33 +195,33 @@ void osmo_stat_item_set(struct osmo_stat_item *item, int32_t value) } /*! Retrieve the next value from the osmo_stat_item object. - * If a new value has been set, it is returned. The idx is used to decide + * If a new value has been set, it is returned. The next_id is used to decide * which value to return. - * On success, *idx is updated to refer to the next unread value. If - * values have been missed due to FIFO overflow, *idx is incremented by + * On success, *next_id is updated to refer to the next unread value. If + * values have been missed due to FIFO overflow, *next_id is incremented by * (1 + num_lost). * This way, the osmo_stat_item object can be kept stateless from the reader's * perspective and therefore be used by several backends simultaneously. * - * \param val the osmo_stat_item object - * \param idx identifies the next value to be read - * \param value a pointer to store the value + * \param val the osmo_stat_item object + * \param next_id identifies the next value to be read + * \param value a pointer to store the value * \returns the increment of the index (0: no value has been read, * 1: one value has been taken, * (1+n): n values have been skipped, one has been taken) */ -int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_idx, +int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_id, int32_t *value) { const struct osmo_stat_item_value *next_value; const struct osmo_stat_item_value *item_value = NULL; - int idx_delta; + int id_delta; int next_offs; next_offs = item->last_offs; next_value = &item->values[next_offs]; - while (next_value->id - *next_idx >= 0 && + while (next_value->id - *next_id >= 0 && next_value->id != OSMO_STAT_ITEM_NOVALUE_ID) { item_value = next_value; @@ -240,27 +240,27 @@ int osmo_stat_item_get_next(const struct osmo_stat_item *item, int32_t *next_idx *value = item_value->value; - idx_delta = item_value->id + 1 - *next_idx; + id_delta = item_value->id + 1 - *next_id; - *next_idx = item_value->id + 1; + *next_id = item_value->id + 1; - return idx_delta; + return id_delta; } -/*! Skip/discard all values of this item and update \a idx accordingly */ -int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *idx) +/*! Skip/discard all values of this item and update \a next_id accordingly */ +int osmo_stat_item_discard(const struct osmo_stat_item *item, int32_t *next_id) { - int discarded = item->values[item->last_offs].id + 1 - *idx; - *idx = item->values[item->last_offs].id + 1; + int discarded = item->values[item->last_offs].id + 1 - *next_id; + *next_id = item->values[item->last_offs].id + 1; return discarded; } -/*! Skip all values of all items and update \a idx accordingly */ -int osmo_stat_item_discard_all(int32_t *idx) +/*! Skip all values of all items and update \a next_id accordingly */ +int osmo_stat_item_discard_all(int32_t *next_id) { - int discarded = global_value_id + 1 - *idx; - *idx = global_value_id + 1; + int discarded = global_value_id + 1 - *next_id; + *next_id = global_value_id + 1; return discarded; } diff --git a/src/stats.c b/src/stats.c index f2820a45..88b733fd 100644 --- a/src/stats.c +++ b/src/stats.c @@ -107,7 +107,7 @@ static LLIST_HEAD(osmo_stats_reporter_list); static void *osmo_stats_ctx = NULL; static int is_initialised = 0; -static int32_t current_stat_item_index = 0; +static int32_t current_stat_item_next_id = 0; static struct osmo_stats_config s_stats_config = { .interval = STATS_DEFAULT_INTERVAL, @@ -241,7 +241,7 @@ void osmo_stats_reporter_free(struct osmo_stats_reporter *srep) void osmo_stats_init(void *ctx) { osmo_stats_ctx = ctx; - osmo_stat_item_discard_all(¤t_stat_item_index); + osmo_stat_item_discard_all(¤t_stat_item_next_id); is_initialised = 1; start_timer(); @@ -694,18 +694,18 @@ static int osmo_stat_item_handler( struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *sctx_) { struct osmo_stats_reporter *srep; - int32_t idx = current_stat_item_index; + int32_t next_id = current_stat_item_next_id; int32_t value; int have_value; - have_value = osmo_stat_item_get_next(item, &idx, &value) > 0; + have_value = osmo_stat_item_get_next(item, &next_id, &value) > 0; if (!have_value) { /* Send the last value in case a flush is requested */ value = osmo_stat_item_get_last(item); } else { int32_t next_val; /* If we have multiple values only send the max */ - while (osmo_stat_item_get_next(item, &idx, &next_val) > 0) + while (osmo_stat_item_get_next(item, &next_id, &next_val) > 0) value = OSMO_MAX(value, next_val); } @@ -798,7 +798,7 @@ int osmo_stats_report() osmo_stat_item_for_each_group(osmo_stat_item_group_handler, NULL); /* global actions */ - osmo_stat_item_discard_all(¤t_stat_item_index); + osmo_stat_item_discard_all(¤t_stat_item_next_id); flush_all_reporters(); TRACE(LIBOSMOCORE_STATS_DONE()); |