X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=doc%2Fexamples%2Frculfhash%2Fcds_lfht_lookup.c;h=8eeacf70bbfadd1383a58b1a5732ee3105131ac0;hb=70469b43316ecc8d6053550504858ad8a8ef9b16;hp=e76827b881d8e80c432357a96f73c930b63f2700;hpb=2dbf31c9e6479b126f67a3494a9b4dfaa57b39b3;p=urcu.git diff --git a/doc/examples/rculfhash/cds_lfht_lookup.c b/doc/examples/rculfhash/cds_lfht_lookup.c index e76827b..8eeacf7 100644 --- a/doc/examples/rculfhash/cds_lfht_lookup.c +++ b/doc/examples/rculfhash/cds_lfht_lookup.c @@ -18,7 +18,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 */ @@ -37,12 +37,12 @@ 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 */ int lookup_values[] = { 42, 200, 36, }; @@ -58,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); @@ -66,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; @@ -98,11 +98,11 @@ 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); printf("Add (key: %d, seqnum: %d)\n", node->value, node->seqnum); - rcu_read_unlock(); + urcu_memb_read_unlock(); } /* @@ -111,12 +111,12 @@ 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"); /* @@ -128,7 +128,7 @@ int main(int argc, char **argv) int value = lookup_values[i]; unsigned long hash = jhash(&value, sizeof(value), seed); - rcu_read_lock(); + urcu_memb_read_lock(); cds_lfht_lookup(ht, hash, match, &value, &iter); ht_node = cds_lfht_iter_get_node(&iter); if (!ht_node) { @@ -138,10 +138,10 @@ int main(int argc, char **argv) printf("(key %d, seqnum %d) found\n", node->value, node->seqnum); } - rcu_read_unlock(); + urcu_memb_read_unlock(); } end: - rcu_unregister_thread(); + urcu_memb_unregister_thread(); return ret; }