rculfhash: constify all key arguments passed to API
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 16 Nov 2011 12:23:19 +0000 (07:23 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 16 Nov 2011 12:23:19 +0000 (07:23 -0500)
The hash table never needs to modify the key, it is only ever used for
"match", so it should always be received as a const argument.

Reported-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rculfhash.c
tests/test_urcu_hash.c
urcu/rculfhash.h

index bda3bd6e5e79b6cae109226430b8a23dc0e85f07..c08447bb1e1e60d84d79667635f2e0e5f3786528 100644 (file)
@@ -318,7 +318,7 @@ struct partition_resize_work {
 static
 void _cds_lfht_add(struct cds_lfht *ht,
                cds_lfht_match_fct match,
-               void *key,
+               const void *key,
                unsigned long size,
                struct cds_lfht_node *node,
                struct cds_lfht_iter *unique_ret,
@@ -890,7 +890,7 @@ int _cds_lfht_replace(struct cds_lfht *ht, unsigned long size,
 static
 void _cds_lfht_add(struct cds_lfht *ht,
                cds_lfht_match_fct match,
-               void *key,
+               const void *key,
                unsigned long size,
                struct cds_lfht_node *node,
                struct cds_lfht_iter *unique_ret,
@@ -1382,7 +1382,7 @@ struct cds_lfht *_cds_lfht_new(unsigned long init_size,
 }
 
 void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash,
-               cds_lfht_match_fct match, void *key,
+               cds_lfht_match_fct match, const void *key,
                struct cds_lfht_iter *iter)
 {
        struct cds_lfht_node *node, *next, *bucket;
@@ -1420,7 +1420,7 @@ void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash,
 }
 
 void cds_lfht_next_duplicate(struct cds_lfht *ht, cds_lfht_match_fct match,
-               void *key, struct cds_lfht_iter *iter)
+               const void *key, struct cds_lfht_iter *iter)
 {
        struct cds_lfht_node *node, *next;
        unsigned long reverse_hash;
@@ -1501,7 +1501,7 @@ void cds_lfht_add(struct cds_lfht *ht, unsigned long hash,
 struct cds_lfht_node *cds_lfht_add_unique(struct cds_lfht *ht,
                                unsigned long hash,
                                cds_lfht_match_fct match,
-                               void *key,
+                               const void *key,
                                struct cds_lfht_node *node)
 {
        unsigned long size;
@@ -1518,7 +1518,7 @@ struct cds_lfht_node *cds_lfht_add_unique(struct cds_lfht *ht,
 struct cds_lfht_node *cds_lfht_add_replace(struct cds_lfht *ht,
                                unsigned long hash,
                                cds_lfht_match_fct match,
-                               void *key,
+                               const void *key,
                                struct cds_lfht_node *node)
 {
        unsigned long size;
index 509767c02e795411ff94cbc5582f589e2d792e31..fe650f36a083a81d08991bf1a6b18c85baccd098 100644 (file)
@@ -384,7 +384,7 @@ void hashword2(
 
 #if (CAA_BITS_PER_LONG == 32)
 static
-unsigned long test_hash(void *_key, size_t length, unsigned long seed)
+unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
 {
        unsigned int key = (unsigned int) _key;
 
@@ -393,7 +393,7 @@ unsigned long test_hash(void *_key, size_t length, unsigned long seed)
 }
 #else
 static
-unsigned long test_hash(void *_key, size_t length, unsigned long seed)
+unsigned long test_hash(const void *_key, size_t length, unsigned long seed)
 {
        union {
                uint64_t v64;
@@ -413,8 +413,8 @@ unsigned long test_hash(void *_key, size_t length, unsigned long seed)
 #endif
 
 static
-unsigned long test_compare(void *key1, size_t key1_len,
-                           void *key2, size_t key2_len)
+unsigned long test_compare(const void *key1, size_t key1_len,
+                           const void *key2, size_t key2_len)
 {
        if (caa_unlikely(key1_len != key2_len))
                return -1;
@@ -426,7 +426,7 @@ unsigned long test_compare(void *key1, size_t key1_len,
 }
 
 static
-int test_match(struct cds_lfht_node *node, void *key)
+int test_match(struct cds_lfht_node *node, const void *key)
 {
        struct lfht_test_node *test_node = to_test_node(node);
 
index c13d3dff91bb7d6dd77ddb81d389420347e8988a..9208011d900b3770184df8ed2d7d5f2106201a13 100644 (file)
@@ -71,7 +71,7 @@ struct cds_lfht;
  * Ensure reader and writer threads are registered as urcu readers.
  */
 
-typedef int (*cds_lfht_match_fct)(struct cds_lfht_node *node, void *key);
+typedef int (*cds_lfht_match_fct)(struct cds_lfht_node *node, const void *key);
 
 /*
  * cds_lfht_node_init - initialize a hash table node
@@ -186,7 +186,7 @@ void cds_lfht_count_nodes(struct cds_lfht *ht,
  * Threads calling this API need to be registered RCU read-side threads.
  */
 void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash,
-               cds_lfht_match_fct match, void *key,
+               cds_lfht_match_fct match, const void *key,
                struct cds_lfht_iter *iter);
 
 /*
@@ -206,7 +206,7 @@ void cds_lfht_lookup(struct cds_lfht *ht, unsigned long hash,
  * Threads calling this API need to be registered RCU read-side threads.
  */
 void cds_lfht_next_duplicate(struct cds_lfht *ht,
-               cds_lfht_match_fct match, void *key,
+               cds_lfht_match_fct match, const void *key,
                struct cds_lfht_iter *iter);
 
 /*
@@ -268,7 +268,7 @@ void cds_lfht_add(struct cds_lfht *ht, unsigned long hash,
 struct cds_lfht_node *cds_lfht_add_unique(struct cds_lfht *ht,
                unsigned long hash,
                cds_lfht_match_fct match,
-               void *key,
+               const void *key,
                struct cds_lfht_node *node);
 
 /*
@@ -300,7 +300,7 @@ struct cds_lfht_node *cds_lfht_add_unique(struct cds_lfht *ht,
 struct cds_lfht_node *cds_lfht_add_replace(struct cds_lfht *ht,
                unsigned long hash,
                cds_lfht_match_fct match,
-               void *key,
+               const void *key,
                struct cds_lfht_node *node);
 
 /*
This page took 0.031253 seconds and 4 git commands to generate.