X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=include%2Furcu%2Frculfhash.h;h=16f7d1cdaa433d47f72aecd31a20b3a99cc2a8fe;hb=e58cdfcfc3884d003b7a0b097fd02c6969382edc;hp=cbf513ec848c37744bb084a72ff66dd19f8c1816;hpb=d7c76f85442125bcfef40f58b1c6fc1bd5ce4ffd;p=urcu.git diff --git a/include/urcu/rculfhash.h b/include/urcu/rculfhash.h index cbf513e..16f7d1c 100644 --- a/include/urcu/rculfhash.h +++ b/include/urcu/rculfhash.h @@ -105,10 +105,20 @@ typedef int (*cds_lfht_match_fct)(struct cds_lfht_node *node, const void *key); * (detection of memory corruption). */ static inline -void cds_lfht_node_init(struct cds_lfht_node *node) +void cds_lfht_node_init(struct cds_lfht_node *node __attribute__((unused))) { } +/* + * cds_lfht_node_init_deleted - initialize a hash table node to "removed" state + * @node: the node to initialize. + * + * Initialize the node such that cds_lfht_is_node_deleted() can be used + * on the node before it is added to a hash table. + */ +extern +void cds_lfht_node_init_deleted(struct cds_lfht_node *node); + /* * Hash table creation flags. */ @@ -237,16 +247,16 @@ struct cds_lfht *cds_lfht_new(unsigned long init_size, * * Return 0 on success, negative error value on error. + * Threads calling this API need to be registered RCU read-side threads. + * * Prior to liburcu 0.10: - * - Threads calling this API need to be registered RCU read-side - * threads. * - cds_lfht_destroy should *not* be called from a RCU read-side * critical section. It should *not* be called from a call_rcu thread * context neither. * * Starting from liburcu 0.10, rculfhash implements its own worker - * thread to handle resize operations, which removes RCU requirements on - * cds_lfht_destroy. + * thread to handle resize operations, which removes the above RCU + * read-side critical section requirement on cds_lfht_destroy. */ extern int cds_lfht_destroy(struct cds_lfht *ht, pthread_attr_t **attr); @@ -499,7 +509,7 @@ int cds_lfht_del(struct cds_lfht *ht, struct cds_lfht_node *node); * This function does not issue any memory barrier. */ extern -int cds_lfht_is_node_deleted(struct cds_lfht_node *node); +int cds_lfht_is_node_deleted(const struct cds_lfht_node *node); /* * cds_lfht_resize - Force a hash table resize @@ -534,24 +544,30 @@ void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size); cds_lfht_next_duplicate(ht, match, key, iter), \ node = cds_lfht_iter_get_node(iter)) +#define cds_lfht_entry(ptr, type, member) \ + ({ \ + caa_unqual_scalar_typeof(ptr) ___ptr = (ptr); \ + ___ptr ? caa_container_of(___ptr, type, member) : NULL; \ + }) + #define cds_lfht_for_each_entry(ht, iter, pos, member) \ for (cds_lfht_first(ht, iter), \ - pos = caa_container_of(cds_lfht_iter_get_node(iter), \ - __typeof__(*(pos)), member); \ - cds_lfht_iter_get_node(iter) != NULL; \ + pos = cds_lfht_entry(cds_lfht_iter_get_node(iter), \ + __typeof__(*(pos)), member); \ + pos != NULL; \ cds_lfht_next(ht, iter), \ - pos = caa_container_of(cds_lfht_iter_get_node(iter), \ - __typeof__(*(pos)), member)) + pos = cds_lfht_entry(cds_lfht_iter_get_node(iter), \ + __typeof__(*(pos)), member)) #define cds_lfht_for_each_entry_duplicate(ht, hash, match, key, \ iter, pos, member) \ for (cds_lfht_lookup(ht, hash, match, key, iter), \ - pos = caa_container_of(cds_lfht_iter_get_node(iter), \ - __typeof__(*(pos)), member); \ - cds_lfht_iter_get_node(iter) != NULL; \ + pos = cds_lfht_entry(cds_lfht_iter_get_node(iter), \ + __typeof__(*(pos)), member); \ + pos != NULL; \ cds_lfht_next_duplicate(ht, match, key, iter), \ - pos = caa_container_of(cds_lfht_iter_get_node(iter), \ - __typeof__(*(pos)), member)) + pos = cds_lfht_entry(cds_lfht_iter_get_node(iter), \ + __typeof__(*(pos)), member)) #ifdef __cplusplus }