X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fhashtable%2Fhashtable.c;h=78175ca6d508d24b2ffd4fa29a82ce8fba3633ff;hb=0afeb879549bcc6202ca0c87ba306377f6261bc3;hp=55346b903bb5a465e23d07d4037f174ea00e9ce1;hpb=d604af56012530c73c1f1b1fbe6156555febe386;p=lttng-tools.git diff --git a/src/common/hashtable/hashtable.c b/src/common/hashtable/hashtable.c index 55346b903..78175ca6d 100644 --- a/src/common/hashtable/hashtable.c +++ b/src/common/hashtable/hashtable.c @@ -15,7 +15,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -28,6 +27,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; @@ -96,6 +98,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"); @@ -250,7 +259,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); @@ -579,12 +588,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); -}