X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_cache.c;h=7c1fa41e42638593b322368442810c6a96574690;hb=51181b899668ad2c232a152d6e5e787c4eb049cc;hp=fa592f0901a6150449877b6597403e3ac39b0165;hpb=21ab7512825cf8177d5eee5101344b45d0854610;p=collectd.git diff --git a/src/daemon/utils_cache.c b/src/daemon/utils_cache.c index fa592f09..7c1fa41e 100644 --- a/src/daemon/utils_cache.c +++ b/src/daemon/utils_cache.c @@ -27,6 +27,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "utils_avltree.h" @@ -135,9 +136,7 @@ static void cache_free (cache_entry_t *ce) static void uc_check_range (const data_set_t *ds, cache_entry_t *ce) { - size_t i; - - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { if (isnan (ce->values_gauge[i])) continue; @@ -153,7 +152,6 @@ static int uc_insert (const data_set_t *ds, const value_list_t *vl, { char *key_copy; cache_entry_t *ce; - size_t i; /* `cache_lock' has been locked by `uc_update' */ @@ -174,7 +172,7 @@ static int uc_insert (const data_set_t *ds, const value_list_t *vl, sstrncpy (ce->name, key, sizeof (ce->name)); - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { switch (ds->ds[i].type) { @@ -253,7 +251,6 @@ int uc_check_timeout (void) c_avl_iterator_t *iter; int status; - int i; pthread_mutex_lock (&cache_lock); @@ -325,7 +322,7 @@ int uc_check_timeout (void) * including plugin specific meta data, rates, history, …. This must be done * without holding the lock, otherwise we will run into a deadlock if a * plugin calls the cache interface. */ - for (i = 0; i < keys_len; i++) + for (int i = 0; i < keys_len; i++) { value_list_t vl = VALUE_LIST_INIT; @@ -350,7 +347,7 @@ int uc_check_timeout (void) * the timestamp again, so in theory it is possible we remove a value after * it is updated here. */ pthread_mutex_lock (&cache_lock); - for (i = 0; i < keys_len; i++) + for (int i = 0; i < keys_len; i++) { key = NULL; ce = NULL; @@ -382,7 +379,6 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) char name[6 * DATA_MAX_NAME_LEN]; cache_entry_t *ce = NULL; int status; - size_t i; if (FORMAT_VL (name, sizeof (name), vl) != 0) { @@ -414,7 +410,7 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) return (-1); } - for (i = 0; i < ds->ds_num; i++) + for (size_t i = 0; i < ds->ds_num; i++) { switch (ds->ds[i].type) { @@ -463,7 +459,7 @@ int uc_update (const data_set_t *ds, const value_list_t *vl) if (ce->history != NULL) { assert (ce->history_index < ce->history_length); - for (i = 0; i < ce->values_num; i++) + for (size_t i = 0; i < ce->values_num; i++) { size_t hist_idx = (ce->values_num * ce->history_index) + i; ce->history[hist_idx] = ce->values_gauge[i]; @@ -643,9 +639,7 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number) if (status != 0) { - size_t i; - - for (i = 0; i < number; i++) + for (size_t i = 0; i < number; i++) { sfree (names[i]); } @@ -720,7 +714,6 @@ int uc_get_history_by_name (const char *name, gauge_t *ret_history, size_t num_steps, size_t num_ds) { cache_entry_t *ce = NULL; - size_t i; int status = 0; pthread_mutex_lock (&cache_lock); @@ -752,7 +745,7 @@ int uc_get_history_by_name (const char *name, return (-ENOMEM); } - for (i = ce->history_length * ce->values_num; + for (size_t i = ce->history_length * ce->values_num; i < (num_steps * ce->values_num); i++) tmp[i] = NAN; @@ -762,7 +755,7 @@ int uc_get_history_by_name (const char *name, } /* if (ce->history_length < num_steps) */ /* Copy the values to the output buffer. */ - for (i = 0; i < num_steps; i++) + for (size_t i = 0; i < num_steps; i++) { size_t src_index; size_t dst_index; @@ -947,8 +940,6 @@ int uc_iterator_get_time (uc_iter_t *iter, cdtime_t *ret_time) int uc_iterator_get_values (uc_iter_t *iter, value_t **ret_values, size_t *ret_num) { - size_t i; - if ((iter == NULL) || (iter->entry == NULL) || (ret_values == NULL) || (ret_num == NULL)) return (-1); @@ -956,7 +947,7 @@ int uc_iterator_get_values (uc_iter_t *iter, value_t **ret_values, size_t *ret_n *ret_values = calloc (iter->entry->values_num, sizeof(*iter->entry->values_raw)); if (*ret_values == NULL) return (-1); - for (i = 0; i < iter->entry->values_num; ++i) + for (size_t i = 0; i < iter->entry->values_num; ++i) *ret_values[i] = iter->entry->values_raw[i]; *ret_num = iter->entry->values_num;