[ltt-dev] [PATCH] lfhash: constify arguments to compare and hash function

Stephen Hemminger shemminger at vyatta.com
Tue Nov 15 23:24:05 EST 2011


The compare and hash functions do not modify key.
---
 tests/test_urcu_hash.c |    8 ++++----
 urcu/rculfhash.h       |    8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c
index 88dd1ae..f45c492 100644
--- a/tests/test_urcu_hash.c
+++ b/tests/test_urcu_hash.c
@@ -295,7 +295,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 long key = (unsigned long) _key;
 	unsigned long v;
@@ -305,7 +305,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;
@@ -325,8 +325,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 (unlikely(key1_len != key2_len))
 		return -1;
diff --git a/urcu/rculfhash.h b/urcu/rculfhash.h
index 37e36b7..4638d28 100644
--- a/urcu/rculfhash.h
+++ b/urcu/rculfhash.h
@@ -56,10 +56,10 @@ struct cds_lfht;
  * Ensure reader and writer threads are registered as urcu readers.
  */
 
-typedef unsigned long (*cds_lfht_hash_fct)(void *key, size_t length,
-					unsigned long seed);
-typedef unsigned long (*cds_lfht_compare_fct)(void *key1, size_t key1_len,
-					void *key2, size_t key2_len);
+typedef unsigned long (*cds_lfht_hash_fct)(const void *key, size_t length,
+					   unsigned long seed);
+typedef unsigned long (*cds_lfht_compare_fct)(const void *key1, size_t key1_len,
+					      const void *key2, size_t key2_len);
 
 /*
  * cds_lfht_node_init - initialize a hash table node
-- 
1.7.7.1





More information about the lttng-dev mailing list