Move to kernel style SPDX license identifiers
[lttng-tools.git] / src / common / hashtable / hashtable.c
index 5b861c8004d04e4f125e2c294cc980f42e0869d6..f449fab8bd6dabab89302b86c9222d0569fc5cf6 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * 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.
- *
- * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #define _LGPL_SOURCE
@@ -27,6 +17,9 @@
 #include "hashtable.h"
 #include "utils.h"
 
+/* seed_lock protects both seed_init and lttng_ht_seed. */
+static pthread_mutex_t seed_lock = PTHREAD_MUTEX_INITIALIZER;
+static bool seed_init;
 unsigned long lttng_ht_seed;
 
 static unsigned long min_hash_alloc_size = 1;
@@ -95,6 +88,13 @@ struct lttng_ht *lttng_ht_new(unsigned long size, int type)
        if (!size)
                size = DEFAULT_HT_SIZE;
 
+       pthread_mutex_lock(&seed_lock);
+       if (!seed_init) {
+               lttng_ht_seed = (unsigned long) time(NULL);
+               seed_init = true;
+       }
+       pthread_mutex_unlock(&seed_lock);
+
        ht = zmalloc(sizeof(*ht));
        if (ht == NULL) {
                PERROR("zmalloc lttng_ht");
@@ -249,7 +249,7 @@ void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node)
  * Lookup function in hashtable.
  */
 LTTNG_HIDDEN
-void lttng_ht_lookup(struct lttng_ht *ht, void *key,
+void lttng_ht_lookup(struct lttng_ht *ht, const void *key,
                struct lttng_ht_iter *iter)
 {
        assert(ht);
@@ -578,12 +578,3 @@ struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(
        }
        return caa_container_of(node, struct lttng_ht_node_two_u64, node);
 }
-
-/*
- * lib constructor
- */
-static void __attribute__((constructor)) _init(void)
-{
-       /* Init hash table seed */
-       lttng_ht_seed = (unsigned long) time(NULL);
-}
This page took 0.024632 seconds and 5 git commands to generate.