/*
- * 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 _GNU_SOURCE
#define _LGPL_SOURCE
#include <assert.h>
#include <string.h>
#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;
/*
* Return an allocated lttng hashtable.
*/
+LTTNG_HIDDEN
struct lttng_ht *lttng_ht_new(unsigned long size, int type)
{
struct lttng_ht *ht;
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");
/*
* Free a lttng hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_destroy(struct lttng_ht *ht)
{
int ret;
/*
* Init lttng ht node string.
*/
+LTTNG_HIDDEN
void lttng_ht_node_init_str(struct lttng_ht_node_str *node, char *key)
{
assert(node);
/*
* Init lttng ht node unsigned long.
*/
+LTTNG_HIDDEN
void lttng_ht_node_init_ulong(struct lttng_ht_node_ulong *node,
unsigned long key)
{
/*
* Init lttng ht node uint64_t.
*/
+LTTNG_HIDDEN
void lttng_ht_node_init_u64(struct lttng_ht_node_u64 *node,
uint64_t key)
{
/*
* Init lttng ht node with two uint64_t.
*/
+LTTNG_HIDDEN
void lttng_ht_node_init_two_u64(struct lttng_ht_node_two_u64 *node,
uint64_t key1, uint64_t key2)
{
/*
* Free lttng ht node string.
*/
+LTTNG_HIDDEN
void lttng_ht_node_free_str(struct lttng_ht_node_str *node)
{
assert(node);
/*
* Free lttng ht node unsigned long.
*/
+LTTNG_HIDDEN
void lttng_ht_node_free_ulong(struct lttng_ht_node_ulong *node)
{
assert(node);
/*
* Free lttng ht node uint64_t.
*/
+LTTNG_HIDDEN
void lttng_ht_node_free_u64(struct lttng_ht_node_u64 *node)
{
assert(node);
/*
* Free lttng ht node two uint64_t.
*/
+LTTNG_HIDDEN
void lttng_ht_node_free_two_u64(struct lttng_ht_node_two_u64 *node)
{
assert(node);
/*
* Lookup function in hashtable.
*/
-void lttng_ht_lookup(struct lttng_ht *ht, void *key,
+LTTNG_HIDDEN
+void lttng_ht_lookup(struct lttng_ht *ht, const void *key,
struct lttng_ht_iter *iter)
{
assert(ht);
/*
* Add unique string node to hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_add_unique_str(struct lttng_ht *ht,
struct lttng_ht_node_str *node)
{
/*
* Add string node to hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_add_str(struct lttng_ht *ht,
struct lttng_ht_node_str *node)
{
/*
* Add unsigned long node to hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_add_ulong(struct lttng_ht *ht, struct lttng_ht_node_ulong *node)
{
assert(ht);
/*
* Add uint64_t node to hashtable.
-
*/
+LTTNG_HIDDEN
void lttng_ht_add_u64(struct lttng_ht *ht, struct lttng_ht_node_u64 *node)
{
assert(ht);
/*
* Add unique unsigned long node to hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_add_unique_ulong(struct lttng_ht *ht,
struct lttng_ht_node_ulong *node)
{
/*
* Add unique uint64_t node to hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_add_unique_u64(struct lttng_ht *ht,
struct lttng_ht_node_u64 *node)
{
/*
* Add unique two uint64_t node to hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_add_unique_two_u64(struct lttng_ht *ht,
struct lttng_ht_node_two_u64 *node)
{
/*
* Add replace unsigned long node to hashtable.
*/
+LTTNG_HIDDEN
struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(struct lttng_ht *ht,
struct lttng_ht_node_ulong *node)
{
/*
* Add replace unsigned long node to hashtable.
*/
+LTTNG_HIDDEN
struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(struct lttng_ht *ht,
struct lttng_ht_node_u64 *node)
{
/*
* Delete node from hashtable.
*/
+LTTNG_HIDDEN
int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter)
{
int ret;
/*
* Get first node in the hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_get_first(struct lttng_ht *ht, struct lttng_ht_iter *iter)
{
assert(ht);
/*
* Get next node in the hashtable.
*/
+LTTNG_HIDDEN
void lttng_ht_get_next(struct lttng_ht *ht, struct lttng_ht_iter *iter)
{
assert(ht);
/*
* Return the number of nodes in the hashtable.
*/
+LTTNG_HIDDEN
unsigned long lttng_ht_get_count(struct lttng_ht *ht)
{
long scb, sca;
/*
* Return lttng ht string node from iterator.
*/
+LTTNG_HIDDEN
struct lttng_ht_node_str *lttng_ht_iter_get_node_str(
struct lttng_ht_iter *iter)
{
/*
* Return lttng ht unsigned long node from iterator.
*/
+LTTNG_HIDDEN
struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(
struct lttng_ht_iter *iter)
{
/*
* Return lttng ht unsigned long node from iterator.
*/
+LTTNG_HIDDEN
struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(
struct lttng_ht_iter *iter)
{
/*
* Return lttng ht stream and index id node from iterator.
*/
+LTTNG_HIDDEN
struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(
struct lttng_ht_iter *iter)
{
}
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);
-}