X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=doc%2Fexamples%2Frculfhash%2Fcds_lfht_destroy.c;h=f0c8219f9194c1fda16330e2498e2d5606f6f3ad;hb=1c87adb3dde9011cc0ac576b5ec622a7c845a06a;hp=d82d81c157858e55a879098a0893d5b2147aa1ff;hpb=d14301c29dfc8761d54c4a289416d67606682675;p=userspace-rcu.git diff --git a/doc/examples/rculfhash/cds_lfht_destroy.c b/doc/examples/rculfhash/cds_lfht_destroy.c index d82d81c..f0c8219 100644 --- a/doc/examples/rculfhash/cds_lfht_destroy.c +++ b/doc/examples/rculfhash/cds_lfht_destroy.c @@ -1,15 +1,8 @@ +// SPDX-FileCopyrightText: 2013 Mathieu Desnoyers +// +// SPDX-License-Identifier: MIT + /* - * Copyright (C) 2013 Mathieu Desnoyers - * - * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED - * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. - * - * Permission is hereby granted to use or copy this program for any - * purpose, provided the above notices are retained on all copies. - * Permission to modify the code and to distribute modified code is - * granted, provided the above notices are retained, and a notice that - * the code was modified is included with the above copyright notice. - * * This example shows how to use cds_lfht_destroy() to clear memory used * by a a RCU lock-free hash table. This hash table requires using a * RCU scheme. @@ -19,7 +12,7 @@ #include #include -#include /* RCU flavor */ +#include /* RCU flavor */ #include /* RCU Lock-free hash table */ #include /* For CAA_ARRAY_SIZE */ #include "jhash.h" /* Example hash function */ @@ -41,7 +34,7 @@ void free_node(struct rcu_head *head) free(node); } -int main(int argc, char **argv) +int main(void) { int values[] = { -5, 42, 42, 36, 24, }; /* 42 is duplicated */ struct cds_lfht *ht; /* Hash table */ @@ -56,7 +49,7 @@ int main(int argc, char **argv) * Each thread need using RCU read-side need to be explicitly * registered. */ - rcu_register_thread(); + urcu_memb_register_thread(); /* Use time as seed for hash table hashing. */ seed = (uint32_t) time(NULL); @@ -64,9 +57,9 @@ int main(int argc, char **argv) /* * Allocate hash table. */ - ht = cds_lfht_new(1, 1, 0, + ht = cds_lfht_new_flavor(1, 1, 0, CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING, - NULL); + &urcu_memb_flavor, NULL); if (!ht) { printf("Error allocating hash table\n"); ret = -1; @@ -95,9 +88,9 @@ int main(int argc, char **argv) * cds_lfht_add() needs to be called from RCU read-side * critical section. */ - rcu_read_lock(); + urcu_memb_read_lock(); cds_lfht_add(ht, hash, &node->node); - rcu_read_unlock(); + urcu_memb_read_unlock(); } /* @@ -106,11 +99,11 @@ int main(int argc, char **argv) * be performed within RCU read-side critical section. */ printf("hash table content (random order):"); - rcu_read_lock(); + urcu_memb_read_lock(); cds_lfht_for_each_entry(ht, &iter, node, node) { printf(" %d", node->value); } - rcu_read_unlock(); + urcu_memb_read_unlock(); printf("\n"); @@ -118,7 +111,7 @@ int main(int argc, char **argv) * Make sure all hash table nodes are removed before destroying. */ printf("removing all nodes:"); - rcu_read_lock(); + urcu_memb_read_lock(); cds_lfht_for_each_entry(ht, &iter, node, node) { ht_node = cds_lfht_iter_get_node(&iter); ret = cds_lfht_del(ht, ht_node); @@ -126,10 +119,10 @@ int main(int argc, char **argv) if (ret) { printf(" (concurrently deleted)"); } else { - call_rcu(&node->rcu_head, free_node); + urcu_memb_call_rcu(&node->rcu_head, free_node); } } - rcu_read_unlock(); + urcu_memb_read_unlock(); printf("\n"); /* @@ -144,6 +137,6 @@ int main(int argc, char **argv) printf("Destroying hash table failed\n"); } end: - rcu_unregister_thread(); + urcu_memb_unregister_thread(); return ret; }