X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=doc%2Fexamples%2Frculfhash%2Fcds_lfht_add.c;h=67b00f40fc0a775fd0d388b84036331279f83525;hp=8932e7acd2f8bfc84f71edf81bb4aa8b0de912de;hb=HEAD;hpb=f7e7a1b86b06da9d2cef60e43039fa8c8ae6479a diff --git a/doc/examples/rculfhash/cds_lfht_add.c b/doc/examples/rculfhash/cds_lfht_add.c index 8932e7a..927e38d 100644 --- a/doc/examples/rculfhash/cds_lfht_add.c +++ b/doc/examples/rculfhash/cds_lfht_add.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 add nodes (allowing duplicate keys) into 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 */ @@ -32,7 +25,7 @@ struct mynode { struct cds_lfht_node node; /* Chaining in hash table */ }; -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 */ @@ -46,7 +39,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); @@ -54,9 +47,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; @@ -83,9 +76,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(); } /* @@ -94,13 +87,13 @@ 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"); end: - rcu_unregister_thread(); + urcu_memb_unregister_thread(); return ret; }