X-Git-Url: https://git.lttng.org/?p=urcu.git;a=blobdiff_plain;f=doc%2Fexamples%2Frculfhash%2Fcds_lfht_del.c;h=4bcf15cd7b2d8facc22df5253eedf9e0bce74f1f;hp=d5a726484a335de620b531a05df029e26643a18d;hb=34b3f359c81e6400c9b451e49bf9dfaef7963509;hpb=650b434b12597af49cad28c5c4b5faa3c98c04b0 diff --git a/doc/examples/rculfhash/cds_lfht_del.c b/doc/examples/rculfhash/cds_lfht_del.c index d5a7264..4bcf15c 100644 --- a/doc/examples/rculfhash/cds_lfht_del.c +++ b/doc/examples/rculfhash/cds_lfht_del.c @@ -32,6 +32,7 @@ struct mynode { struct rcu_head rcu_head; /* For call_rcu() */ }; +static int match(struct cds_lfht_node *ht_node, const void *_key) { struct mynode *node = @@ -41,6 +42,14 @@ int match(struct cds_lfht_node *ht_node, const void *_key) return *key == node->value; } +static +void free_node(struct rcu_head *head) +{ + struct mynode *node = caa_container_of(head, struct mynode, rcu_head); + + free(node); +} + int main(int argc, char **argv) { int values[] = { -5, 42, 42, 36, 24, }; /* 42 is duplicated */ @@ -132,6 +141,11 @@ int main(int argc, char **argv) ret = cds_lfht_del(ht, ht_node); if (ret) { printf(" (concurrently deleted)"); + } else { + struct mynode *del_node = + caa_container_of(ht_node, + struct mynode, node); + call_rcu(&del_node->rcu_head, free_node); } } else { printf(" (not found)");