diff --git a/TODO-RELEASE b/TODO-RELEASE index 369668193..a4d9dfbd8 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -16,3 +16,4 @@ gsm API/ABI change add new member to lapd_datalink gsm new API new gsm0808_create_common_id() gb new API new bssgp_tx_bvc_reset2() core new API new rate_ctr_reset(), rate_ctr_group_reset() +core new API new osmo_stat_item_reset(), osmo_stat_item_group_reset() diff --git a/include/osmocom/core/stat_item.h b/include/osmocom/core/stat_item.h index 806173abf..4710dba71 100644 --- a/include/osmocom/core/stat_item.h +++ b/include/osmocom/core/stat_item.h @@ -114,4 +114,8 @@ static inline int32_t osmo_stat_item_get_last(const struct osmo_stat_item *item) { return item->values[item->last_offs].value; } + +void osmo_stat_item_reset(struct osmo_stat_item *item); +void osmo_stat_item_group_reset(struct osmo_stat_item_group *statg); + /*! @} */ diff --git a/src/stat_item.c b/src/stat_item.c index 67165754a..ba3646406 100644 --- a/src/stat_item.c +++ b/src/stat_item.c @@ -356,4 +356,33 @@ int osmo_stat_item_for_each_group(osmo_stat_item_group_handler_t handle_group, v return rc; } + +/*! Remove all values of a stat item + * \param[in] item stat item to reset + */ +void osmo_stat_item_reset(struct osmo_stat_item *item) +{ + unsigned int i; + + item->last_offs = item->desc->num_values - 1; + item->last_value_index = -1; + + for (i = 0; i <= item->last_offs; i++) { + item->values[i].value = item->desc->default_value; + item->values[i].id = OSMO_STAT_ITEM_NOVALUE_ID; + } +} + +/*! Reset all osmo stat items in a group + * \param[in] statg stat item group to reset + */ +void osmo_stat_item_group_reset(struct osmo_stat_item_group *statg) +{ + int i; + + for (i = 0; i < statg->desc->num_items; i++) { + struct osmo_stat_item *item = statg->items[i]; + osmo_stat_item_reset(item); + } +} /*! @} */