From 4c10e9af6fb29192621372ab9077860f3c1b179f Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 10 Jan 2022 15:35:53 -0500 Subject: [PATCH] rculfhash: introduce cds_lfht_node_init_deleted Allow initializing lfht node to "removed" state to allow querying whether the node is published in a hash table before it is added to the hash table and after it has been removed from the hash table. Signed-off-by: Mathieu Desnoyers Change-Id: I6e364a3ea076f33e34b4c63c7b23be22b35e9bb1 --- include/urcu/rculfhash.h | 10 ++++++++++ src/rculfhash.c | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/urcu/rculfhash.h b/include/urcu/rculfhash.h index 29dd88f..8586e1d 100644 --- a/include/urcu/rculfhash.h +++ b/include/urcu/rculfhash.h @@ -109,6 +109,16 @@ 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. */ diff --git a/src/rculfhash.c b/src/rculfhash.c index 04fd499..8046f3a 100644 --- a/src/rculfhash.c +++ b/src/rculfhash.c @@ -851,6 +851,12 @@ int is_removal_owner(struct cds_lfht_node *node) return ((unsigned long) node) & REMOVAL_OWNER_FLAG; } +static +struct cds_lfht_node *flag_removed(struct cds_lfht_node *node) +{ + return (struct cds_lfht_node *) (((unsigned long) node) | REMOVED_FLAG); +} + static struct cds_lfht_node *flag_removal_owner(struct cds_lfht_node *node) { @@ -1578,6 +1584,12 @@ const struct cds_lfht_mm_type *get_mm_type( } #endif +void cds_lfht_node_init_deleted(struct cds_lfht_node *node) +{ + cds_lfht_node_init(node); + node->next = flag_removed(NULL); +} + struct cds_lfht *_cds_lfht_new(unsigned long init_size, unsigned long min_nr_alloc_buckets, unsigned long max_nr_buckets, -- 2.34.1