X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdtool.c;h=dc06d68a100eac4013b6080d9027df154345135a;hb=f71467d9c2097ddd9eb772a4fdb985663168ec71;hp=d274ba021b65146cd2cf7195421e045c52a1f5d5;hpb=b400d28e853eea66d6f233a3524009dea01d9e41;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index d274ba02..dc06d68a 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -105,7 +105,7 @@ static double xff = 0.1; static int cache_timeout = 0; static int cache_flush_timeout = 0; static time_t cache_flush_last; -static avl_tree_t *cache = NULL; +static c_avl_tree_t *cache = NULL; static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER; static rrd_queue_t *queue_head = NULL; @@ -641,7 +641,7 @@ static void *rrd_queue_thread (void *data) * we make a copy of it's values */ pthread_mutex_lock (&cache_lock); - avl_get (cache, queue_entry->filename, (void *) &cache_entry); + c_avl_get (cache, queue_entry->filename, (void *) &cache_entry); values = cache_entry->values; values_num = cache_entry->values_num; @@ -654,6 +654,8 @@ static void *rrd_queue_thread (void *data) /* Write the values to the RRD-file */ srrd_update (queue_entry->filename, NULL, values_num, values); + DEBUG ("rrdtool plugin: queue thread: Wrote %i values to %s", + values_num, queue_entry->filename); for (i = 0; i < values_num; i++) { @@ -665,7 +667,7 @@ static void *rrd_queue_thread (void *data) } /* while (42) */ pthread_mutex_lock (&cache_lock); - avl_destroy (cache); + c_avl_destroy (cache); cache = NULL; pthread_mutex_unlock (&cache_lock); @@ -713,7 +715,7 @@ static void rrd_cache_flush (int timeout) int keys_num = 0; char *key; - avl_iterator_t *iter; + c_avl_iterator_t *iter; int i; DEBUG ("rrdtool plugin: Flushing cache, timeout = %i", timeout); @@ -721,8 +723,8 @@ static void rrd_cache_flush (int timeout) now = time (NULL); /* Build a list of entries to be flushed */ - iter = avl_get_iterator (cache); - while (avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0) + iter = c_avl_get_iterator (cache); + while (c_avl_iterator_next (iter, (void *) &key, (void *) &rc) == 0) { if (rc->flags == FLAG_QUEUED) continue; @@ -735,29 +737,31 @@ static void rrd_cache_flush (int timeout) } else /* ancient and no values -> waste of memory */ { - keys = (char **) realloc ((void *) keys, + char **tmp = (char **) realloc ((void *) keys, (keys_num + 1) * sizeof (char *)); - if (keys == NULL) + if (tmp == NULL) { char errbuf[1024]; ERROR ("rrdtool plugin: " "realloc failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); - avl_iterator_destroy (iter); + c_avl_iterator_destroy (iter); + sfree (keys); return; } + keys = tmp; keys[keys_num] = key; keys_num++; } - } /* while (avl_iterator_next) */ - avl_iterator_destroy (iter); + } /* while (c_avl_iterator_next) */ + c_avl_iterator_destroy (iter); for (i = 0; i < keys_num; i++) { - if (avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0) + if (c_avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0) { - DEBUG ("rrdtool plugin: avl_remove (%s) failed.", keys[i]); + DEBUG ("rrdtool plugin: c_avl_remove (%s) failed.", keys[i]); continue; } @@ -769,7 +773,7 @@ static void rrd_cache_flush (int timeout) keys[i] = NULL; } /* for (i = 0..keys_num) */ - free (keys); + sfree (keys); cache_flush_last = now; } /* void rrd_cache_flush */ @@ -783,7 +787,7 @@ static int rrd_cache_insert (const char *filename, pthread_mutex_lock (&cache_lock); - avl_get (cache, filename, (void *) &rc); + c_avl_get (cache, filename, (void *) &rc); if (rc == NULL) { @@ -816,7 +820,7 @@ static int rrd_cache_insert (const char *filename, sstrerror (errno, errbuf, sizeof (errbuf)); - avl_remove (cache, filename, &cache_key, NULL); + c_avl_remove (cache, filename, &cache_key, NULL); pthread_mutex_unlock (&cache_lock); ERROR ("rrdtool plugin: realloc failed: %s", errbuf); @@ -856,7 +860,7 @@ static int rrd_cache_insert (const char *filename, return (-1); } - avl_insert (cache, cache_key, rc); + c_avl_insert (cache, cache_key, rc); } DEBUG ("rrdtool plugin: rrd_cache_insert: file = %s; " @@ -1095,10 +1099,10 @@ static int rrd_init (void) /* Set the cache up */ pthread_mutex_lock (&cache_lock); - cache = avl_create ((int (*) (const void *, const void *)) strcmp); + cache = c_avl_create ((int (*) (const void *, const void *)) strcmp); if (cache == NULL) { - ERROR ("rrdtool plugin: avl_create failed."); + ERROR ("rrdtool plugin: c_avl_create failed."); return (-1); }