From bd5041ead24263c4da911a4e64eec361728c05bb Mon Sep 17 00:00:00 2001 From: Simone Mainardi Date: Mon, 18 Nov 2019 11:35:43 +0100 Subject: [PATCH] Renames walkIdle to walkAllStates and documents method behavior --- include/GenericHash.h | 19 +++++++++++++------ src/GenericHash.cpp | 2 +- src/NetworkInterface.cpp | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/GenericHash.h b/include/GenericHash.h index 05d439d89e..c4e128fe22 100644 --- a/include/GenericHash.h +++ b/include/GenericHash.h @@ -107,8 +107,10 @@ class GenericHash { bool add(GenericHashEntry *h, bool do_lock); /** - * @brief generic walker for the hash. - * @details This method uses the walker function to compare each elements of the hash with the user data. + * @brief Generic hash table walker + * @details This method traverses all the non-idle entries of the hash table, calling + * the walker function on each of them. Function idle() is called for each entry + * to evaluate its state, determine if the entry is idle, and possibly call the walker. * * @param begin_slot begin hash slot. Use 0 to walk all slots * @param walk_all true = walk all hash, false, walk only one (non NULL) slot @@ -119,14 +121,19 @@ class GenericHash { bool (*walker)(GenericHashEntry *h, void *user_data, bool *entryMatched), void *user_data); /** - * @brief Hash table walker used only by an offline thread in charge of deleting idle entries - * @details This method walks the hash table and the idle_entries vector to perform cleanup operations - * on idle entries, before calling the destructor on them + * @brief Hash table walker used only by an offline thread in charge of performing entries state changes + * @details This method traverses all the entries of the hash table, including those that are idle + * and have been previously placed in the idle_entries vector, calling the walker function + * on each of them. Entries found in the idle_entries vector are deleted right after the call + * of the walker function against them. + * This method should only be called by an offline thread in charge of performing entries state changes (e.g., from + * protocol detected to activ) and operations associated to entries state changes (e.g., the + * call of a lua script against the entry). * * @param walker A pointer to the comparison function. * @param user_data Value to be compared with the values of hash. */ - void walkIdle(bool (*walker)(GenericHashEntry *h, void *user_data), void *user_data); + void walkAllStates(bool (*walker)(GenericHashEntry *h, void *user_data), void *user_data); /** * @brief Purge idle hash entries. diff --git a/src/GenericHash.cpp b/src/GenericHash.cpp index 2ed76f53f6..2c0eeedf32 100644 --- a/src/GenericHash.cpp +++ b/src/GenericHash.cpp @@ -122,7 +122,7 @@ bool GenericHash::add(GenericHashEntry *h, bool do_lock) { /* ************************************ */ -void GenericHash::walkIdle(bool (*walker)(GenericHashEntry *h, void *user_data), void *user_data) { +void GenericHash::walkAllStates(bool (*walker)(GenericHashEntry *h, void *user_data), void *user_data) { vector *cur_idle = NULL; u_int new_walk_idle_start_hash_id = 0; bool update_walk_idle_start_hash_id; diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index fc7db46914..34c5d3521c 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -2810,7 +2810,7 @@ void NetworkInterface::periodicHTStateUpdate(time_t deadline, lua_State* vm) { for(u_int i = 0; i < sizeof(ghs) / sizeof(ghs[0]); i++) { if(ghs[i]) { - ghs[i]->walkIdle(generic_periodic_hash_entry_state_update, &periodic_ht_state_update_user_data); + ghs[i]->walkAllStates(generic_periodic_hash_entry_state_update, &periodic_ht_state_update_user_data); if(periodic_ht_state_update_user_data.acle) { periodic_ht_state_update_user_data.acle->lua_stats(ghs[i]->getName(), vm);