} /* void cache_free */
static int uc_insert(metric_t const *m, char const *key) {
- /* `cache_lock' has been locked by `uc_update' */
+ // cache_lock has been locked by uc_update().
+ // uc_init has been called by uc_update().
char *key_copy = strdup(key);
if (key_copy == NULL) {
return 0;
} /* int uc_insert */
-int uc_init(void) {
- if (cache_tree == NULL) {
- cache_tree = c_avl_create(cache_compare);
+static void uc_init(void) {
+ if (cache_tree != NULL) {
+ return;
}
-
- return 0;
-} /* int uc_init */
+ cache_tree = c_avl_create(cache_compare);
+}
int uc_check_timeout(void) {
struct {
size_t expired_num = 0;
pthread_mutex_lock(&cache_lock);
+ uc_init();
+
cdtime_t now = cdtime();
/* Build a list of entries to be flushed */
}
pthread_mutex_lock(&cache_lock);
+ uc_init();
cache_entry_t *ce = NULL;
status = c_avl_get(cache_tree, buf.ptr, (void *)&ce);
int uc_set_callbacks_mask(const char *name, unsigned long mask) {
pthread_mutex_lock(&cache_lock);
+ uc_init();
+
cache_entry_t *ce = NULL;
int status = c_avl_get(cache_tree, name, (void *)&ce);
if (status != 0) { /* Ouch, just created entry disappeared ?! */
}
DEBUG("uc_set_callbacks_mask: set mask for \"%s\" to %lu.", name, mask);
ce->callbacks_mask = mask;
+
pthread_mutex_unlock(&cache_lock);
return 0;
}
int status = 0;
pthread_mutex_lock(&cache_lock);
+ uc_init();
if (c_avl_get(cache_tree, name, (void *)&ce) == 0) {
assert(ce != NULL);
int uc_get_value_by_name(const char *name, value_t *ret_values) {
pthread_mutex_lock(&cache_lock);
+ uc_init();
cache_entry_t *ce = NULL;
int status = 0;
}
pthread_mutex_unlock(&cache_lock);
-
return status;
} /* int uc_get_value_by_name */
} /* value_t *uc_get_value */
static int uc_get_first_time_by_name(const char *name, cdtime_t *ret_time) {
+ uc_init();
+
cache_entry_t *ce = NULL;
int err = c_avl_get(cache_tree, name, (void *)&ce);
if (err == ENOENT) {
}
size_t uc_get_size(void) {
- size_t size_arrays = 0;
-
pthread_mutex_lock(&cache_lock);
- size_arrays = (size_t)c_avl_size(cache_tree);
- pthread_mutex_unlock(&cache_lock);
+ uc_init();
+
+ size_t size_arrays = (size_t)c_avl_size(cache_tree);
+ pthread_mutex_unlock(&cache_lock);
return size_arrays;
}
return -1;
pthread_mutex_lock(&cache_lock);
+ uc_init();
size_arrays = (size_t)c_avl_size(cache_tree);
if (size_arrays < 1) {
}
pthread_mutex_lock(&cache_lock);
+ uc_init();
cache_entry_t *ce = NULL;
int ret = STATE_ERROR;
}
pthread_mutex_unlock(&cache_lock);
-
STRBUF_DESTROY(buf);
return ret;
} /* int uc_get_state */
}
pthread_mutex_lock(&cache_lock);
+ uc_init();
cache_entry_t *ce = NULL;
int ret = -1;
}
pthread_mutex_unlock(&cache_lock);
-
STRBUF_DESTROY(buf);
return ret;
} /* int uc_set_state */
int status = 0;
pthread_mutex_lock(&cache_lock);
+ uc_init();
status = c_avl_get(cache_tree, name, (void *)&ce);
if (status != 0) {
}
pthread_mutex_unlock(&cache_lock);
-
return 0;
} /* int uc_get_history_by_name */
}
pthread_mutex_lock(&cache_lock);
+ uc_init();
cache_entry_t *ce = NULL;
int ret = STATE_ERROR;
}
pthread_mutex_unlock(&cache_lock);
-
STRBUF_DESTROY(buf);
return ret;
} /* int uc_get_hits */
}
pthread_mutex_lock(&cache_lock);
+ uc_init();
cache_entry_t *ce = NULL;
int ret = -1;
}
pthread_mutex_unlock(&cache_lock);
-
STRBUF_DESTROY(buf);
return ret;
} /* int uc_set_hits */
}
pthread_mutex_lock(&cache_lock);
+ uc_init();
cache_entry_t *ce = NULL;
int ret = -1;
}
pthread_mutex_unlock(&cache_lock);
-
STRBUF_DESTROY(buf);
return ret;
} /* int uc_inc_hits */
return NULL;
pthread_mutex_lock(&cache_lock);
+ uc_init();
iter->iter = c_avl_get_iterator(cache_tree);
if (iter->iter == NULL) {
while ((status = c_avl_iterator_next(iter->iter, (void *)&iter->name,
(void *)&iter->entry)) == 0) {
- if (iter->entry->state == STATE_MISSING)
+ if (iter->entry->state == STATE_MISSING) {
continue;
+ }
break;
}
* Meta data interface
*/
/* XXX: Must hold cache_lock when calling this function! */
-static meta_data_t *uc_get_meta(metric_t const *m) /* {{{ */
-{
+static meta_data_t *uc_get_meta(metric_t const *m) {
+ uc_init();
+
strbuf_t buf = STRBUF_CREATE;
int status = metric_identity(&buf, m);
if (status != 0) {
}
return ce->meta;
-} /* }}} meta_data_t *uc_get_meta */
+}
/* Sorry about this preprocessor magic, but it really makes this file much
* shorter.. */