X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_hash.h;h=fe13c36ad192c890fda33a21b049daaa91bee3e4;hp=a935e94b0a095bac4fccf9a693b18842d3f027d0;hb=bd252a04bbbb163aa4d8864b1e1e5a3a4d9d0892;hpb=20adf7802bcec449566b9cbb900504fd409f62db diff --git a/tests/test_urcu_hash.h b/tests/test_urcu_hash.h index a935e94..fe13c36 100644 --- a/tests/test_urcu_hash.h +++ b/tests/test_urcu_hash.h @@ -37,6 +37,8 @@ #include #include +#include + #ifdef __linux__ #include #endif @@ -102,13 +104,13 @@ struct wr_count { unsigned long remove; }; -extern unsigned int __thread rand_lookup; -extern unsigned long __thread nr_add; -extern unsigned long __thread nr_addexist; -extern unsigned long __thread nr_del; -extern unsigned long __thread nr_delnoent; -extern unsigned long __thread lookup_fail; -extern unsigned long __thread lookup_ok; +extern DECLARE_URCU_TLS(unsigned int, rand_lookup); +extern DECLARE_URCU_TLS(unsigned long, nr_add); +extern DECLARE_URCU_TLS(unsigned long, nr_addexist); +extern DECLARE_URCU_TLS(unsigned long, nr_del); +extern DECLARE_URCU_TLS(unsigned long, nr_delnoent); +extern DECLARE_URCU_TLS(unsigned long, lookup_fail); +extern DECLARE_URCU_TLS(unsigned long, lookup_ok); extern struct cds_lfht *test_ht; @@ -169,6 +171,8 @@ extern unsigned long init_pool_size, write_pool_size; extern int validate_lookup; +extern unsigned long nr_hash_chains; + extern int count_pipe[2]; static inline void loop_sleep(unsigned long l) @@ -212,8 +216,8 @@ static inline int test_duration_read(void) return !test_stop; } -extern unsigned long long __thread nr_writes; -extern unsigned long long __thread nr_reads; +extern DECLARE_URCU_TLS(unsigned long long, nr_writes); +extern DECLARE_URCU_TLS(unsigned long long, nr_reads); extern unsigned int nr_readers; extern unsigned int nr_writers; @@ -323,7 +327,7 @@ void hashword2( #if (CAA_BITS_PER_LONG == 32) static inline -unsigned long test_hash(const void *_key, size_t length, unsigned long seed) +unsigned long test_hash_mix(const void *_key, size_t length, unsigned long seed) { unsigned int key = (unsigned int) _key; @@ -332,7 +336,7 @@ unsigned long test_hash(const void *_key, size_t length, unsigned long seed) } #else static inline -unsigned long test_hash(const void *_key, size_t length, unsigned long seed) +unsigned long test_hash_mix(const void *_key, size_t length, unsigned long seed) { union { uint64_t v64; @@ -351,6 +355,29 @@ unsigned long test_hash(const void *_key, size_t length, unsigned long seed) } #endif +/* + * Hash function with nr_hash_chains != 0 for testing purpose only! + * Creates very long hash chains, deteriorating the hash table into a + * few linked lists, depending on the nr_hash_chains value. The purpose + * of this test is to check how the hash table behaves with hash chains + * containing different values, which is a rare case in a normal hash + * table. + */ +static inline +unsigned long test_hash(const void *_key, size_t length, + unsigned long seed) +{ + if (nr_hash_chains == 0) { + return test_hash_mix(_key, length, seed); + } else { + unsigned long v; + + assert(length == sizeof(unsigned long)); + v = (unsigned long) _key; + return v % nr_hash_chains; + } +} + unsigned long test_compare(const void *key1, size_t key1_len, const void *key2, size_t key2_len);