2 * collectd - src/utils_cache.c
3 * Copyright (C) 2007,2008 Florian octo Forster
4 * Copyright (C) 2010 Andrés J. Díaz
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; only version 2 of the License is applicable.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Florian octo Forster <octo at verplant.org>
21 * Andrés J. Díaz <ajdiaz at connectical.com>
27 #include "utils_avltree.h"
28 #include "utils_cache.h"
29 #include "utils_threshold.h"
30 #include "utils_subst.h"
31 #include "meta_data.h"
36 typedef struct cache_entry_s
38 char name[6 * DATA_MAX_NAME_LEN];
40 gauge_t *values_gauge;
42 /* Time contained in the package
43 * (for calculating rates) */
45 /* Time according to the local clock
46 * (for purging old entries) */
48 /* Interval in which the data is collected
49 * (for purding old entries) */
55 * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
56 * ! 0 ! 1 ! 2 ! 3 ! 4 ! 5 ! 6 ! 7 ! 8 ! ...
57 * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
58 * ! ds0 ! ds1 ! ds2 ! ds0 ! ds1 ! ds2 ! ds0 ! ds1 ! ds2 ! ...
59 * +-----+-----+-----+-----+-----+-----+-----+-----+-----+----
60 * ! t = 0 ! t = 1 ! t = 2 ! ...
61 * +-----------------+-----------------+-----------------+----
64 size_t history_index; /* points to the next position to write to. */
65 size_t history_length;
70 static c_avl_tree_t *cache_tree = NULL;
71 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
73 static int cache_compare (const cache_entry_t *a, const cache_entry_t *b)
75 assert ((a != NULL) && (b != NULL));
76 return (strcmp (a->name, b->name));
77 } /* int cache_compare */
79 static cache_entry_t *cache_alloc (int values_num)
83 ce = (cache_entry_t *) malloc (sizeof (cache_entry_t));
86 ERROR ("utils_cache: cache_alloc: malloc failed.");
89 memset (ce, '\0', sizeof (cache_entry_t));
90 ce->values_num = values_num;
92 ce->values_gauge = calloc (values_num, sizeof (*ce->values_gauge));
93 ce->values_raw = calloc (values_num, sizeof (*ce->values_raw));
94 if ((ce->values_gauge == NULL) || (ce->values_raw == NULL))
96 sfree (ce->values_gauge);
97 sfree (ce->values_raw);
99 ERROR ("utils_cache: cache_alloc: calloc failed.");
104 ce->history_length = 0;
108 } /* cache_entry_t *cache_alloc */
110 static void cache_free (cache_entry_t *ce)
115 sfree (ce->values_gauge);
116 sfree (ce->values_raw);
118 if (ce->meta != NULL)
120 meta_data_destroy (ce->meta);
124 } /* void cache_free */
126 static int uc_send_notification (const char *name)
128 cache_entry_t *ce = NULL;
134 char *plugin_instance;
144 name_copy = strdup (name);
145 if (name_copy == NULL)
147 ERROR ("uc_send_notification: strdup failed.");
151 status = parse_identifier (name_copy, &host,
152 &plugin, &plugin_instance,
153 &type, &type_instance);
156 ERROR ("uc_send_notification: Cannot parse name `%s'", name);
160 memset (&ds, '\0', sizeof (ds));
161 memset (&vl, '\0', sizeof (vl));
162 sstrncpy (vl.host, host, sizeof (vl.host));
163 sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
164 if (plugin_instance != NULL)
165 sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
166 sstrncpy (ds.type, type, sizeof (ds.type));
167 sstrncpy (vl.type, type, sizeof (vl.type));
168 if (type_instance != NULL)
169 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
171 /* Copy the associative members */
172 notification_init (&n, NOTIF_FAILURE, /* host = */ NULL,
173 host, plugin, plugin_instance, type, type_instance);
176 name_copy = host = plugin = plugin_instance = type = type_instance = NULL;
178 pthread_mutex_lock (&cache_lock);
181 * Set the time _after_ getting the lock because we don't know how long
182 * acquiring the lock takes and we will use this time later to decide
183 * whether or not the state is OKAY.
185 n.time = time (NULL);
187 status = c_avl_get (cache_tree, name, (void *) &ce);
190 pthread_mutex_unlock (&cache_lock);
194 /* Check if the entry has been updated in the meantime */
195 if ((n.time - ce->last_update) < (2 * ce->interval))
197 ce->state = STATE_OKAY;
198 pthread_mutex_unlock (&cache_lock);
202 /* if the associated threshold has a missing message, then use custom
203 * message. FIXME: we do a threshold_search here and in uc_check_timeout
204 * (calling ut_check_interesting, but we really need to do this once */
205 if ( !ut_search_threshold(&vl, &th) &&
206 (th.missing_message != NULL) )
208 char msg[NOTIF_MAX_MSG_LEN];
209 char temp[NOTIF_MAX_MSG_LEN];
210 char missing[NOTIF_MAX_MSG_LEN];
212 sstrncpy (msg, th.missing_message, sizeof (msg));
213 ut_build_message (msg, sizeof (msg), th.missing_message,
214 &ds, /* ds index = */ 0, &vl, ce->values_gauge,
217 ssnprintf (missing, sizeof(missing), "%li",
218 (long int) (n.time - ce->last_update));
219 if (subst_string (temp, sizeof (temp), msg, "%{missing}", missing) != NULL)
220 sstrncpy (msg, temp, sizeof (msg));
222 sstrncpy (n.message, msg, sizeof (n.message));
226 ssnprintf (n.message, sizeof (n.message),
227 "%s has not been updated for %i seconds.", name,
228 (int) (n.time - ce->last_update));
231 pthread_mutex_unlock (&cache_lock);
233 plugin_dispatch_notification (&n);
236 } /* int uc_send_notification */
238 static void uc_check_range (const data_set_t *ds, cache_entry_t *ce)
242 for (i = 0; i < ds->ds_num; i++)
244 if (isnan (ce->values_gauge[i]))
246 else if (ce->values_gauge[i] < ds->ds[i].min)
247 ce->values_gauge[i] = NAN;
248 else if (ce->values_gauge[i] > ds->ds[i].max)
249 ce->values_gauge[i] = NAN;
251 } /* void uc_check_range */
253 static int uc_insert (const data_set_t *ds, const value_list_t *vl,
260 /* `cache_lock' has been locked by `uc_update' */
262 key_copy = strdup (key);
263 if (key_copy == NULL)
265 ERROR ("uc_insert: strdup failed.");
269 ce = cache_alloc (ds->ds_num);
273 ERROR ("uc_insert: cache_alloc (%i) failed.", ds->ds_num);
277 sstrncpy (ce->name, key, sizeof (ce->name));
279 for (i = 0; i < ds->ds_num; i++)
281 switch (ds->ds[i].type)
283 case DS_TYPE_COUNTER:
284 ce->values_gauge[i] = NAN;
285 ce->values_raw[i].counter = vl->values[i].counter;
289 ce->values_gauge[i] = vl->values[i].gauge;
290 ce->values_raw[i].gauge = vl->values[i].gauge;
294 ce->values_gauge[i] = NAN;
295 ce->values_raw[i].derive = vl->values[i].derive;
298 case DS_TYPE_ABSOLUTE:
299 ce->values_gauge[i] = NAN;
300 if (vl->interval > 0)
301 ce->values_gauge[i] = ((double) vl->values[i].absolute)
302 / ((double) vl->interval);
303 ce->values_raw[i].absolute = vl->values[i].absolute;
307 /* This shouldn't happen. */
308 ERROR ("uc_insert: Don't know how to handle data source type %i.",
311 } /* switch (ds->ds[i].type) */
314 /* Prune invalid gauge data */
315 uc_check_range (ds, ce);
317 ce->last_time = vl->time;
318 ce->last_update = time (NULL);
319 ce->interval = vl->interval;
320 ce->state = STATE_OKAY;
322 if (c_avl_insert (cache_tree, key_copy, ce) != 0)
325 ERROR ("uc_insert: c_avl_insert failed.");
329 DEBUG ("uc_insert: Added %s to the cache.", key);
331 } /* int uc_insert */
335 if (cache_tree == NULL)
336 cache_tree = c_avl_create ((int (*) (const void *, const void *))
342 int uc_check_timeout (void)
351 c_avl_iterator_t *iter;
354 pthread_mutex_lock (&cache_lock);
358 /* Build a list of entries to be flushed */
359 iter = c_avl_get_iterator (cache_tree);
360 while (c_avl_iterator_next (iter, (void *) &key, (void *) &ce) == 0)
362 /* If entry has not been updated, add to `keys' array */
363 if ((now - ce->last_update) >= (timeout_g * ce->interval))
367 tmp = (char **) realloc ((void *) keys,
368 (keys_len + 1) * sizeof (char *));
371 ERROR ("uc_check_timeout: realloc failed.");
372 c_avl_iterator_destroy (iter);
374 pthread_mutex_unlock (&cache_lock);
379 keys[keys_len] = strdup (key);
380 if (keys[keys_len] == NULL)
382 ERROR ("uc_check_timeout: strdup failed.");
387 } /* while (c_avl_iterator_next) */
391 for (i = 0; i < keys_len; i++)
395 status = ut_check_interesting (keys[i]);
399 ERROR ("uc_check_timeout: ut_check_interesting failed.");
403 else if (status == 0) /* ``service'' is uninteresting */
405 DEBUG ("uc_check_timeout: %s is missing but ``uninteresting''",
408 status = c_avl_remove (cache_tree, keys[i],
409 (void *) &key, (void *) &ce);
412 ERROR ("uc_check_timeout: c_avl_remove (%s) failed.", keys[i]);
421 /* If we get here, the value is ``interesting''. Query the record from the
422 * cache and update the state field. */
423 if (c_avl_get (cache_tree, keys[i], (void *) &ce) != 0)
425 ERROR ("uc_check_timeout: cannot get data for %s from cache", keys[i]);
426 /* Do not free `keys[i]' so a notification is sent further down. */
431 if (status == 2) /* persist */
433 DEBUG ("uc_check_timeout: %s is missing, sending notification.",
435 ce->state = STATE_MISSING;
436 /* Do not free `keys[i]' so a notification is sent further down. */
438 else if (status == 1) /* do not persist */
440 if (ce->state == STATE_MISSING)
442 DEBUG ("uc_check_timeout: %s is missing but "
443 "notification has already been sent.",
445 /* Set `keys[i]' to NULL to no notification is sent. */
448 else /* (ce->state != STATE_MISSING) */
450 DEBUG ("uc_check_timeout: %s is missing, sending one notification.",
452 ce->state = STATE_MISSING;
453 /* Do not free `keys[i]' so a notification is sent further down. */
458 WARNING ("uc_check_timeout: ut_check_interesting (%s) returned "
459 "invalid status %i.",
464 /* Make really sure the next iteration doesn't work with this pointer.
465 * There have been too many bugs in the past.. :/ -- octo */
467 } /* for (keys[i]) */
469 c_avl_iterator_destroy (iter);
471 pthread_mutex_unlock (&cache_lock);
473 for (i = 0; i < keys_len; i++)
478 uc_send_notification (keys[i]);
485 } /* int uc_check_timeout */
487 int uc_update (const data_set_t *ds, const value_list_t *vl)
489 char name[6 * DATA_MAX_NAME_LEN];
490 cache_entry_t *ce = NULL;
491 int send_okay_notification = 0;
492 time_t update_delay = 0;
497 if (FORMAT_VL (name, sizeof (name), vl) != 0)
499 ERROR ("uc_update: FORMAT_VL failed.");
503 pthread_mutex_lock (&cache_lock);
505 status = c_avl_get (cache_tree, name, (void *) &ce);
506 if (status != 0) /* entry does not yet exist */
508 status = uc_insert (ds, vl, name);
509 pthread_mutex_unlock (&cache_lock);
514 assert (ce->values_num == ds->ds_num);
516 if (ce->last_time >= vl->time)
518 pthread_mutex_unlock (&cache_lock);
519 NOTICE ("uc_update: Value too old: name = %s; value time = %u; "
520 "last cache update = %u;",
521 name, (unsigned int) vl->time, (unsigned int) ce->last_time);
525 /* Send a notification (after the lock has been released) if we switch the
526 * state from something else to `okay'. */
527 if (ce->state == STATE_MISSING)
529 send_okay_notification = 1;
530 ce->state = STATE_OKAY;
531 update_delay = time (NULL) - ce->last_update;
534 for (i = 0; i < ds->ds_num; i++)
536 switch (ds->ds[i].type)
538 case DS_TYPE_COUNTER:
542 /* check if the counter has wrapped around */
543 if (vl->values[i].counter < ce->values_raw[i].counter)
545 if (ce->values_raw[i].counter <= 4294967295U)
546 diff = (4294967295U - ce->values_raw[i].counter)
547 + vl->values[i].counter;
549 diff = (18446744073709551615ULL - ce->values_raw[i].counter)
550 + vl->values[i].counter;
552 else /* counter has NOT wrapped around */
554 diff = vl->values[i].counter - ce->values_raw[i].counter;
557 ce->values_gauge[i] = ((double) diff)
558 / ((double) (vl->time - ce->last_time));
559 ce->values_raw[i].counter = vl->values[i].counter;
564 ce->values_raw[i].gauge = vl->values[i].gauge;
565 ce->values_gauge[i] = vl->values[i].gauge;
572 diff = vl->values[i].derive - ce->values_raw[i].derive;
574 ce->values_gauge[i] = ((double) diff)
575 / ((double) (vl->time - ce->last_time));
576 ce->values_raw[i].derive = vl->values[i].derive;
580 case DS_TYPE_ABSOLUTE:
581 ce->values_gauge[i] = ((double) vl->values[i].absolute)
582 / ((double) (vl->time - ce->last_time));
583 ce->values_raw[i].absolute = vl->values[i].absolute;
587 /* This shouldn't happen. */
588 pthread_mutex_unlock (&cache_lock);
589 ERROR ("uc_update: Don't know how to handle data source type %i.",
592 } /* switch (ds->ds[i].type) */
594 DEBUG ("uc_update: %s: ds[%i] = %lf", name, i, ce->values_gauge[i]);
597 /* Update the history if it exists. */
598 if (ce->history != NULL)
600 assert (ce->history_index < ce->history_length);
601 for (i = 0; i < ce->values_num; i++)
603 size_t hist_idx = (ce->values_num * ce->history_index) + i;
604 ce->history[hist_idx] = ce->values_gauge[i];
607 assert (ce->history_length > 0);
608 ce->history_index = (ce->history_index + 1) % ce->history_length;
611 /* Prune invalid gauge data */
612 uc_check_range (ds, ce);
614 ce->last_time = vl->time;
615 ce->last_update = time (NULL);
616 ce->interval = vl->interval;
618 pthread_mutex_unlock (&cache_lock);
620 if (send_okay_notification == 0)
623 /* Do not send okay notifications for uninteresting values, i. e. values for
624 * which no threshold is configured. */
625 status = ut_check_interesting (name);
629 /* Initialize the notification */
630 memset (&n, '\0', sizeof (n));
631 NOTIFICATION_INIT_VL (&n, vl, ds);
633 n.severity = NOTIF_OKAY;
636 ssnprintf (n.message, sizeof (n.message),
637 "Received a value for %s. It was missing for %u seconds.",
638 name, (unsigned int) update_delay);
640 plugin_dispatch_notification (&n);
643 } /* int uc_update */
645 int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_values_num)
649 cache_entry_t *ce = NULL;
652 pthread_mutex_lock (&cache_lock);
654 if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
658 /* remove missing values from getval */
659 if (ce->state == STATE_MISSING)
665 ret_num = ce->values_num;
666 ret = (gauge_t *) malloc (ret_num * sizeof (gauge_t));
669 ERROR ("utils_cache: uc_get_rate_by_name: malloc failed.");
674 memcpy (ret, ce->values_gauge, ret_num * sizeof (gauge_t));
680 DEBUG ("utils_cache: uc_get_rate_by_name: No such value: %s", name);
684 pthread_mutex_unlock (&cache_lock);
689 *ret_values_num = ret_num;
693 } /* gauge_t *uc_get_rate_by_name */
695 gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl)
697 char name[6 * DATA_MAX_NAME_LEN];
702 if (FORMAT_VL (name, sizeof (name), vl) != 0)
704 ERROR ("utils_cache: uc_get_rate: FORMAT_VL failed.");
708 status = uc_get_rate_by_name (name, &ret, &ret_num);
712 /* This is important - the caller has no other way of knowing how many
713 * values are returned. */
714 if (ret_num != (size_t) ds->ds_num)
716 ERROR ("utils_cache: uc_get_rate: ds[%s] has %i values, "
717 "but uc_get_rate_by_name returned %zu.",
718 ds->type, ds->ds_num, ret_num);
724 } /* gauge_t *uc_get_rate */
726 int uc_get_names (char ***ret_names, time_t **ret_times, size_t *ret_number)
728 c_avl_iterator_t *iter;
730 cache_entry_t *value;
733 time_t *times = NULL;
738 if ((ret_names == NULL) || (ret_number == NULL))
741 pthread_mutex_lock (&cache_lock);
743 iter = c_avl_get_iterator (cache_tree);
744 while (c_avl_iterator_next (iter, (void *) &key, (void *) &value) == 0)
748 /* remove missing values when list values */
749 if (value->state == STATE_MISSING)
752 if (ret_times != NULL)
756 tmp_times = (time_t *) realloc (times, sizeof (time_t) * (number + 1));
757 if (tmp_times == NULL)
763 times[number] = value->last_time;
766 temp = (char **) realloc (names, sizeof (char *) * (number + 1));
773 names[number] = strdup (key);
774 if (names[number] == NULL)
780 } /* while (c_avl_iterator_next) */
782 c_avl_iterator_destroy (iter);
783 pthread_mutex_unlock (&cache_lock);
789 for (i = 0; i < number; i++)
799 if (ret_times != NULL)
801 *ret_number = number;
804 } /* int uc_get_names */
806 int uc_get_state (const data_set_t *ds, const value_list_t *vl)
808 char name[6 * DATA_MAX_NAME_LEN];
809 cache_entry_t *ce = NULL;
810 int ret = STATE_ERROR;
812 if (FORMAT_VL (name, sizeof (name), vl) != 0)
814 ERROR ("uc_get_state: FORMAT_VL failed.");
815 return (STATE_ERROR);
818 pthread_mutex_lock (&cache_lock);
820 if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
826 pthread_mutex_unlock (&cache_lock);
829 } /* int uc_get_state */
831 int uc_set_state (const data_set_t *ds, const value_list_t *vl, int state)
833 char name[6 * DATA_MAX_NAME_LEN];
834 cache_entry_t *ce = NULL;
837 if (FORMAT_VL (name, sizeof (name), vl) != 0)
839 ERROR ("uc_get_state: FORMAT_VL failed.");
840 return (STATE_ERROR);
843 pthread_mutex_lock (&cache_lock);
845 if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
852 pthread_mutex_unlock (&cache_lock);
855 } /* int uc_set_state */
857 int uc_get_history_by_name (const char *name,
858 gauge_t *ret_history, size_t num_steps, size_t num_ds)
860 cache_entry_t *ce = NULL;
864 pthread_mutex_lock (&cache_lock);
866 status = c_avl_get (cache_tree, name, (void *) &ce);
869 pthread_mutex_unlock (&cache_lock);
873 if (((size_t) ce->values_num) != num_ds)
875 pthread_mutex_unlock (&cache_lock);
879 /* Check if there are enough values available. If not, increase the buffer
881 if (ce->history_length < num_steps)
886 tmp = realloc (ce->history, sizeof (*ce->history)
887 * num_steps * ce->values_num);
890 pthread_mutex_unlock (&cache_lock);
894 for (i = ce->history_length * ce->values_num;
895 i < (num_steps * ce->values_num);
900 ce->history_length = num_steps;
901 } /* if (ce->history_length < num_steps) */
903 /* Copy the values to the output buffer. */
904 for (i = 0; i < num_steps; i++)
909 if (i < ce->history_index)
910 src_index = ce->history_index - (i + 1);
912 src_index = ce->history_length + ce->history_index - (i + 1);
913 src_index = src_index * num_ds;
915 dst_index = i * num_ds;
917 memcpy (ret_history + dst_index, ce->history + src_index,
918 sizeof (*ret_history) * num_ds);
921 pthread_mutex_unlock (&cache_lock);
924 } /* int uc_get_history_by_name */
926 int uc_get_history (const data_set_t *ds, const value_list_t *vl,
927 gauge_t *ret_history, size_t num_steps, size_t num_ds)
929 char name[6 * DATA_MAX_NAME_LEN];
931 if (FORMAT_VL (name, sizeof (name), vl) != 0)
933 ERROR ("utils_cache: uc_get_history: FORMAT_VL failed.");
937 return (uc_get_history_by_name (name, ret_history, num_steps, num_ds));
938 } /* int uc_get_history */
940 int uc_get_hits (const data_set_t *ds, const value_list_t *vl)
942 char name[6 * DATA_MAX_NAME_LEN];
943 cache_entry_t *ce = NULL;
944 int ret = STATE_ERROR;
946 if (FORMAT_VL (name, sizeof (name), vl) != 0)
948 ERROR ("uc_get_state: FORMAT_VL failed.");
949 return (STATE_ERROR);
952 pthread_mutex_lock (&cache_lock);
954 if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
960 pthread_mutex_unlock (&cache_lock);
963 } /* int uc_get_hits */
965 int uc_set_hits (const data_set_t *ds, const value_list_t *vl, int hits)
967 char name[6 * DATA_MAX_NAME_LEN];
968 cache_entry_t *ce = NULL;
971 if (FORMAT_VL (name, sizeof (name), vl) != 0)
973 ERROR ("uc_get_state: FORMAT_VL failed.");
974 return (STATE_ERROR);
977 pthread_mutex_lock (&cache_lock);
979 if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
986 pthread_mutex_unlock (&cache_lock);
989 } /* int uc_set_hits */
991 int uc_inc_hits (const data_set_t *ds, const value_list_t *vl, int step)
993 char name[6 * DATA_MAX_NAME_LEN];
994 cache_entry_t *ce = NULL;
997 if (FORMAT_VL (name, sizeof (name), vl) != 0)
999 ERROR ("uc_get_state: FORMAT_VL failed.");
1000 return (STATE_ERROR);
1003 pthread_mutex_lock (&cache_lock);
1005 if (c_avl_get (cache_tree, name, (void *) &ce) == 0)
1007 assert (ce != NULL);
1009 ce->hits = ret + step;
1012 pthread_mutex_unlock (&cache_lock);
1015 } /* int uc_inc_hits */
1018 * Meta data interface
1020 /* XXX: This function will acquire `cache_lock' but will not free it! */
1021 static meta_data_t *uc_get_meta (const value_list_t *vl) /* {{{ */
1023 char name[6 * DATA_MAX_NAME_LEN];
1024 cache_entry_t *ce = NULL;
1027 status = FORMAT_VL (name, sizeof (name), vl);
1030 ERROR ("utils_cache: uc_get_meta: FORMAT_VL failed.");
1034 pthread_mutex_lock (&cache_lock);
1036 status = c_avl_get (cache_tree, name, (void *) &ce);
1039 pthread_mutex_unlock (&cache_lock);
1042 assert (ce != NULL);
1044 if (ce->meta == NULL)
1045 ce->meta = meta_data_create ();
1047 if (ce->meta == NULL)
1048 pthread_mutex_unlock (&cache_lock);
1051 } /* }}} meta_data_t *uc_get_meta */
1053 /* Sorry about this preprocessor magic, but it really makes this file much
1055 #define UC_WRAP(wrap_function) { \
1056 meta_data_t *meta; \
1058 meta = uc_get_meta (vl); \
1059 if (meta == NULL) return (-1); \
1060 status = wrap_function (meta, key); \
1061 pthread_mutex_unlock (&cache_lock); \
1064 int uc_meta_data_exists (const value_list_t *vl, const char *key)
1065 UC_WRAP (meta_data_exists)
1067 int uc_meta_data_delete (const value_list_t *vl, const char *key)
1068 UC_WRAP (meta_data_delete)
1071 /* We need a new version of this macro because the following functions take
1073 #define UC_WRAP(wrap_function) { \
1074 meta_data_t *meta; \
1076 meta = uc_get_meta (vl); \
1077 if (meta == NULL) return (-1); \
1078 status = wrap_function (meta, key, value); \
1079 pthread_mutex_unlock (&cache_lock); \
1082 int uc_meta_data_add_string (const value_list_t *vl,
1085 UC_WRAP(meta_data_add_string)
1086 int uc_meta_data_add_signed_int (const value_list_t *vl,
1089 UC_WRAP(meta_data_add_signed_int)
1090 int uc_meta_data_add_unsigned_int (const value_list_t *vl,
1093 UC_WRAP(meta_data_add_unsigned_int)
1094 int uc_meta_data_add_double (const value_list_t *vl,
1097 UC_WRAP(meta_data_add_double)
1098 int uc_meta_data_add_boolean (const value_list_t *vl,
1101 UC_WRAP(meta_data_add_boolean)
1103 int uc_meta_data_get_string (const value_list_t *vl,
1106 UC_WRAP(meta_data_get_string)
1107 int uc_meta_data_get_signed_int (const value_list_t *vl,
1110 UC_WRAP(meta_data_get_signed_int)
1111 int uc_meta_data_get_unsigned_int (const value_list_t *vl,
1114 UC_WRAP(meta_data_get_unsigned_int)
1115 int uc_meta_data_get_double (const value_list_t *vl,
1118 UC_WRAP(meta_data_get_double)
1119 int uc_meta_data_get_boolean (const value_list_t *vl,
1122 UC_WRAP(meta_data_get_boolean)
1125 /* vim: set sw=2 ts=8 sts=2 tw=78 : */