From ce715b44c1886c8e44f0c6fbac0bff4a80ef3f8c Mon Sep 17 00:00:00 2001 From: liuwentan Date: Thu, 9 Mar 2023 11:26:00 +0800 Subject: fix flagScan update bug --- src/entry/rcu_hash.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/entry/rcu_hash.cpp') diff --git a/src/entry/rcu_hash.cpp b/src/entry/rcu_hash.cpp index 5062787..70712de 100644 --- a/src/entry/rcu_hash.cpp +++ b/src/entry/rcu_hash.cpp @@ -198,12 +198,12 @@ void rcu_hash_add(struct rcu_hash_table *htable, const char *key, size_t key_len if (htable->effective_hash == 'a') { HASH_FIND(hh_b, htable->hashmap_b, key, key_len, tmp); if (NULL == tmp) { - HASH_ADD_KEYPTR(hh_b, htable->hashmap_b, key, key_len, node); + HASH_ADD_KEYPTR(hh_b, htable->hashmap_b, node->key, node->key_len, node); } } else { HASH_FIND(hh_a, htable->hashmap_a, key, key_len, tmp); if (NULL == tmp) { - HASH_ADD_KEYPTR(hh_a, htable->hashmap_a, key, key_len, node); + HASH_ADD_KEYPTR(hh_a, htable->hashmap_a, node->key, node->key_len, node); } } } @@ -272,6 +272,15 @@ size_t rcu_hash_count(struct rcu_hash_table *htable) } } +int rcu_hash_is_updating(struct rcu_hash_table *htable) +{ + if (NULL == htable) { + return 0; + } + + return htable->is_updating; +} + void rcu_hash_commit(struct rcu_hash_table *htable) { if (NULL == htable) { @@ -313,32 +322,27 @@ void rcu_hash_commit(struct rcu_hash_table *htable) pthread_mutex_unlock(&htable->update_mutex); } -size_t rcu_hash_list_updating_data(struct rcu_hash_table *htable, void ***data_array) +size_t rcu_hash_list(struct rcu_hash_table *htable, void ***data_array) { size_t i = 0; size_t node_cnt = 0; struct rcu_hash_node *node = NULL, *tmp = NULL; if (htable->effective_hash == 'a') { - node_cnt = HASH_CNT(hh_b, htable->hashmap_b); + node_cnt = HASH_CNT(hh_a, htable->hashmap_a); *data_array = ALLOC(void *, node_cnt); - HASH_ITER(hh_b, htable->hashmap_b, node, tmp) { + HASH_ITER(hh_a, htable->hashmap_a, node, tmp) { (*data_array)[i] = node->data; i++; } } else { - node_cnt = HASH_CNT(hh_a, htable->hashmap_a); + node_cnt = HASH_CNT(hh_b, htable->hashmap_b); *data_array = ALLOC(void *, node_cnt); - HASH_ITER(hh_a, htable->hashmap_a, node, tmp) { + HASH_ITER(hh_b, htable->hashmap_b, node, tmp) { (*data_array)[i] = node->data; i++; } } return node_cnt; -} - -int rcu_hash_updating_flag(struct rcu_hash_table *htable) -{ - return htable->is_updating; } \ No newline at end of file -- cgit v1.2.3