X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=doc%2Fexamples%2Frculfhash%2Fcds_lfht_add_unique.c;h=d6044c244492e17bab204c6b43b863971198e862;hb=70469b43316ecc8d6053550504858ad8a8ef9b16;hp=ec594c803961b8b12ff5c328a33d50192d96ede6;hpb=650b434b12597af49cad28c5c4b5faa3c98c04b0;p=urcu.git diff --git a/doc/examples/rculfhash/cds_lfht_add_unique.c b/doc/examples/rculfhash/cds_lfht_add_unique.c index ec594c8..d6044c2 100644 --- a/doc/examples/rculfhash/cds_lfht_add_unique.c +++ b/doc/examples/rculfhash/cds_lfht_add_unique.c @@ -19,7 +19,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 */ @@ -33,16 +33,17 @@ struct mynode { struct cds_lfht_node node; /* Chaining in hash table */ }; +static int match(struct cds_lfht_node *ht_node, const void *_key) { struct mynode *node = caa_container_of(ht_node, struct mynode, node); - const unsigned int *key = _key; + const int *key = _key; return *key == node->value; } -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 */ @@ -57,7 +58,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); @@ -65,9 +66,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; @@ -97,7 +98,7 @@ 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(); ht_node = cds_lfht_add_unique(ht, hash, match, &value, &node->node); /* @@ -113,14 +114,14 @@ int main(int argc, char **argv) * match. It did not add the new node to the * hash table, so we can free it on the spot. */ - printf("Not adding duplicate key: %d, seqnum: %d\n", + printf("Not adding duplicate (key: %d, seqnum: %d)\n", node->value, node->seqnum); free(node); } else { - printf("Add key: %d, seqnum: %d\n", + printf("Add (key: %d, seqnum: %d)\n", node->value, node->seqnum); } - rcu_read_unlock(); + urcu_memb_read_unlock(); } /* @@ -129,15 +130,15 @@ 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(" (key: %d, seqnum: %d)", node->value, node->seqnum); } - rcu_read_unlock(); + urcu_memb_read_unlock(); printf("\n"); end: - rcu_unregister_thread(); + urcu_memb_unregister_thread(); return ret; }