X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fhashtable%2Fhashtable.cpp;h=29d3ac499715f1e9da4e8eb8d7b4c79b2c786157;hb=56047f5a23df5c2c583a102b8015bbec5a7da9f1;hp=840a7347936dabb11132eb56b838f961bf3e9bfb;hpb=28ab034a2c3582d07d3423d2d746731f87d3969f;p=lttng-tools.git diff --git a/src/common/hashtable/hashtable.cpp b/src/common/hashtable/hashtable.cpp index 840a73479..29d3ac499 100644 --- a/src/common/hashtable/hashtable.cpp +++ b/src/common/hashtable/hashtable.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -104,13 +105,13 @@ struct lttng_ht *lttng_ht_new(unsigned long size, lttng_ht_type type) pthread_mutex_lock(&seed_lock); if (!seed_init) { - lttng_ht_seed = (unsigned long) time(NULL); + lttng_ht_seed = (unsigned long) time(nullptr); seed_init = true; } pthread_mutex_unlock(&seed_lock); ht = zmalloc(); - if (ht == NULL) { + if (ht == nullptr) { PERROR("zmalloc lttng_ht"); goto error; } @@ -119,7 +120,7 @@ struct lttng_ht *lttng_ht_new(unsigned long size, lttng_ht_type type) min_hash_alloc_size, max_hash_buckets_size, CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, - NULL); + nullptr); /* * There is already an assert in the RCU hashtable code so if the ht is * NULL here there is a *huge* problem. @@ -154,7 +155,7 @@ struct lttng_ht *lttng_ht_new(unsigned long size, lttng_ht_type type) return ht; error: - return NULL; + return nullptr; } /* @@ -164,7 +165,7 @@ void lttng_ht_destroy(struct lttng_ht *ht) { int ret; - ret = cds_lfht_destroy(ht->ht, NULL); + ret = cds_lfht_destroy(ht->ht, nullptr); LTTNG_ASSERT(!ret); free(ht); } @@ -272,13 +273,12 @@ void lttng_ht_add_unique_str(struct lttng_ht *ht, struct lttng_ht_node_str *node LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; node_ptr = cds_lfht_add_unique(ht->ht, ht->hash_fct(node->key, lttng_ht_seed), ht->match_fct, node->key, &node->node); - rcu_read_unlock(); LTTNG_ASSERT(node_ptr == &node->node); } @@ -292,9 +292,8 @@ void lttng_ht_add_str(struct lttng_ht *ht, struct lttng_ht_node_str *node) LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; cds_lfht_add(ht->ht, ht->hash_fct(node->key, lttng_ht_seed), &node->node); - rcu_read_unlock(); } /* @@ -307,9 +306,8 @@ void lttng_ht_add_ulong(struct lttng_ht *ht, struct lttng_ht_node_ulong *node) LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; cds_lfht_add(ht->ht, ht->hash_fct((void *) node->key, lttng_ht_seed), &node->node); - rcu_read_unlock(); } /* @@ -322,9 +320,8 @@ void lttng_ht_add_u64(struct lttng_ht *ht, struct lttng_ht_node_u64 *node) LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; cds_lfht_add(ht->ht, ht->hash_fct(&node->key, lttng_ht_seed), &node->node); - rcu_read_unlock(); } /* @@ -338,13 +335,12 @@ void lttng_ht_add_unique_ulong(struct lttng_ht *ht, struct lttng_ht_node_ulong * LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; node_ptr = cds_lfht_add_unique(ht->ht, ht->hash_fct((void *) node->key, lttng_ht_seed), ht->match_fct, (void *) node->key, &node->node); - rcu_read_unlock(); LTTNG_ASSERT(node_ptr == &node->node); } @@ -359,13 +355,12 @@ void lttng_ht_add_unique_u64(struct lttng_ht *ht, struct lttng_ht_node_u64 *node LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; node_ptr = cds_lfht_add_unique(ht->ht, ht->hash_fct(&node->key, lttng_ht_seed), ht->match_fct, &node->key, &node->node); - rcu_read_unlock(); LTTNG_ASSERT(node_ptr == &node->node); } @@ -380,13 +375,12 @@ void lttng_ht_add_unique_two_u64(struct lttng_ht *ht, struct lttng_ht_node_two_u LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; node_ptr = cds_lfht_add_unique(ht->ht, ht->hash_fct((void *) &node->key, lttng_ht_seed), ht->match_fct, (void *) &node->key, &node->node); - rcu_read_unlock(); LTTNG_ASSERT(node_ptr == &node->node); } @@ -402,19 +396,17 @@ struct lttng_ht_node_ulong *lttng_ht_add_replace_ulong(struct lttng_ht *ht, LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; node_ptr = cds_lfht_add_replace(ht->ht, ht->hash_fct((void *) node->key, lttng_ht_seed), ht->match_fct, (void *) node->key, &node->node); - rcu_read_unlock(); if (!node_ptr) { - return NULL; + return nullptr; } else { return lttng::utils::container_of(node_ptr, <tng_ht_node_ulong::node); } - LTTNG_ASSERT(node_ptr == &node->node); } /* @@ -429,19 +421,18 @@ struct lttng_ht_node_u64 *lttng_ht_add_replace_u64(struct lttng_ht *ht, LTTNG_ASSERT(node); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; node_ptr = cds_lfht_add_replace(ht->ht, ht->hash_fct(&node->key, lttng_ht_seed), ht->match_fct, &node->key, &node->node); - rcu_read_unlock(); if (!node_ptr) { - return NULL; + return nullptr; } else { + LTTNG_ASSERT(node_ptr == &node->node); return lttng::utils::container_of(node_ptr, <tng_ht_node_u64::node); } - LTTNG_ASSERT(node_ptr == &node->node); } /* @@ -456,9 +447,8 @@ int lttng_ht_del(struct lttng_ht *ht, struct lttng_ht_iter *iter) LTTNG_ASSERT(iter); /* RCU read lock protects from ABA. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; ret = cds_lfht_del(ht->ht, iter->iter.node); - rcu_read_unlock(); return ret; } @@ -498,9 +488,8 @@ unsigned long lttng_ht_get_count(struct lttng_ht *ht) LTTNG_ASSERT(ht->ht); /* RCU read lock protects from ABA and allows RCU traversal. */ - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; cds_lfht_count_nodes(ht->ht, &scb, &count, &sca); - rcu_read_unlock(); return count; } @@ -515,7 +504,7 @@ struct lttng_ht_node_str *lttng_ht_iter_get_node_str(struct lttng_ht_iter *iter) LTTNG_ASSERT(iter); node = cds_lfht_iter_get_node(&iter->iter); if (!node) { - return NULL; + return nullptr; } return lttng::utils::container_of(node, <tng_ht_node_str::node); } @@ -530,7 +519,7 @@ struct lttng_ht_node_ulong *lttng_ht_iter_get_node_ulong(struct lttng_ht_iter *i LTTNG_ASSERT(iter); node = cds_lfht_iter_get_node(&iter->iter); if (!node) { - return NULL; + return nullptr; } return lttng::utils::container_of(node, <tng_ht_node_ulong::node); } @@ -545,7 +534,7 @@ struct lttng_ht_node_u64 *lttng_ht_iter_get_node_u64(struct lttng_ht_iter *iter) LTTNG_ASSERT(iter); node = cds_lfht_iter_get_node(&iter->iter); if (!node) { - return NULL; + return nullptr; } return lttng::utils::container_of(node, <tng_ht_node_u64::node); } @@ -560,7 +549,7 @@ struct lttng_ht_node_two_u64 *lttng_ht_iter_get_node_two_u64(struct lttng_ht_ite LTTNG_ASSERT(iter); node = cds_lfht_iter_get_node(&iter->iter); if (!node) { - return NULL; + return nullptr; } return lttng::utils::container_of(node, <tng_ht_node_two_u64::node); }