Merge remote-tracking branch 'origin/pr/603'
[collectd.git] / src / utils_cache.c
index 539545a..9d86781 100644 (file)
@@ -2,20 +2,25 @@
  * collectd - src/utils_cache.c
  * Copyright (C) 2007-2010  Florian octo Forster
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; only version 2 of the License is applicable.
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
  *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
- * Author:
+ * Authors:
  *   Florian octo Forster <octo at collectd.org>
  **/
 
@@ -68,7 +73,9 @@ static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
 
 static int cache_compare (const cache_entry_t *a, const cache_entry_t *b)
 {
+#if COLLECT_DEBUG
   assert ((a != NULL) && (b != NULL));
+#endif
   return (strcmp (a->name, b->name));
 } /* int cache_compare */
 
@@ -574,18 +581,6 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
   size_t number = 0;
   size_t size_arrays = 0;
 
-  /* Increment size for the 2 arrays of values 
-   * Because realloc is time consuming, it's better to
-   * realloc by blocks and not by units.
-   * To see the difference, set this value to 1.
-   *
-   * To change this value at compile time:
-   * ./configure CPPFLAGS="-DLISTVAL_INCREASE=102400"
-   */ 
-#ifndef LISTVAL_INCREASE
-# define LISTVAL_INCREASE 1024
-#endif
-
   int status = 0;
 
   if ((ret_names == NULL) || (ret_number == NULL))
@@ -598,7 +593,7 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
   {
     /* Handle the "no values" case here, to avoid the error message when
      * calloc() returns NULL. */
-    pthread_mutex_lock (&cache_lock);
+    pthread_mutex_unlock (&cache_lock);
     return (0);
   }
 
@@ -609,7 +604,7 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
     ERROR ("uc_get_names: calloc failed.");
     sfree (names);
     sfree (times);
-    pthread_mutex_lock (&cache_lock);
+    pthread_mutex_unlock (&cache_lock);
     return (ENOMEM);
   }