doc/examples: cds_lfht_add_replace
[urcu.git] / doc / examples / rculfhash / cds_lfht_del.c
index d5a726484a335de620b531a05df029e26643a18d..4bcf15cd7b2d8facc22df5253eedf9e0bce74f1f 100644 (file)
@@ -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)");
This page took 0.022811 seconds and 4 git commands to generate.