X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_vl_lookup.c;h=f85910e1737e7b5d1c328a6e9e15896be2d60d99;hb=55ef2778ade050e2924eeb027c98feea103f1585;hp=722c45230fce5669f34d999a644a0a186a9273c5;hpb=16202999622d778521903ca2feef7d55c5b1b5b3;p=collectd.git diff --git a/src/utils_vl_lookup.c b/src/utils_vl_lookup.c index 722c4523..f85910e1 100644 --- a/src/utils_vl_lookup.c +++ b/src/utils_vl_lookup.c @@ -1,6 +1,6 @@ /** * collectd - src/utils_vl_lookup.c - * Copyright (C) 2012 Florian Forster + * Copyright (C) 2012 Florian Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -26,12 +26,17 @@ #include "collectd.h" +#include #include #include "common.h" #include "utils_vl_lookup.h" #include "utils_avltree.h" +#if HAVE_LIBKSTAT +kstat_ctl_t *kc; +#endif /* HAVE_LIBKSTAT */ + #if BUILD_TEST # define sstrncpy strncpy # define plugin_log(s, ...) do { \ @@ -86,6 +91,7 @@ struct user_obj_s struct user_class_s { + pthread_mutex_t lock; void *user_class; identifier_match_t match; user_obj_t *user_obj_list; /* list of user_obj */ @@ -191,6 +197,7 @@ static int lu_copy_ident_to_match (identifier_match_t *match, /* {{{ */ return (0); } /* }}} int lu_copy_ident_to_match */ +/* user_class->lock must be held when calling this function */ static void *lu_create_user_obj (lookup_t *obj, /* {{{ */ data_set_t const *ds, value_list_t const *vl, user_class_t *user_class) @@ -245,6 +252,7 @@ static void *lu_create_user_obj (lookup_t *obj, /* {{{ */ return (user_obj); } /* }}} void *lu_create_user_obj */ +/* user_class->lock must be held when calling this function */ static user_obj_t *lu_find_user_obj (user_class_t *user_class, /* {{{ */ value_list_t const *vl) { @@ -294,14 +302,18 @@ static int lu_handle_user_class (lookup_t *obj, /* {{{ */ || !lu_part_matches (&user_class->match.host, vl->host)) return (1); + pthread_mutex_lock (&user_class->lock); user_obj = lu_find_user_obj (user_class, vl); if (user_obj == NULL) { /* call lookup_class_callback_t() and insert into the list of user objects. */ user_obj = lu_create_user_obj (obj, ds, vl, user_class); - if (user_obj == NULL) + if (user_obj == NULL) { + pthread_mutex_unlock (&user_class->lock); return (-1); + } } + pthread_mutex_unlock (&user_class->lock); status = obj->cb_user_obj (ds, vl, user_class->user_class, user_obj->user_obj); @@ -402,7 +414,7 @@ static int lu_add_by_plugin (by_type_entry_t *by_type, /* {{{ */ identifier_match_t const *match = &user_class_list->entry.match; /* Lookup user_class_list from the per-plugin structure. If this is the first - * user_class to be added, the blocks return immediately. Otherwise they will + * user_class to be added, the block returns immediately. Otherwise they will * set "ptr" to non-NULL. */ if (match->plugin.is_regex) { @@ -487,6 +499,7 @@ static void lu_destroy_user_class_list (lookup_t *obj, /* {{{ */ lu_destroy_user_obj (obj, user_class_list->entry.user_obj_list); user_class_list->entry.user_obj_list = NULL; + pthread_mutex_destroy (&user_class_list->entry.lock); sfree (user_class_list); user_class_list = next; @@ -599,6 +612,7 @@ int lookup_add (lookup_t *obj, /* {{{ */ return (ENOMEM); } memset (user_class_obj, 0, sizeof (*user_class_obj)); + pthread_mutex_init (&user_class_obj->entry.lock, /* attr = */ NULL); user_class_obj->entry.user_class = user_class; lu_copy_ident_to_match (&user_class_obj->entry.match, ident, group_by); user_class_obj->entry.user_obj_list = NULL;