diff --git a/src/3rdparty/tommyds/tommyhashdyn.c b/src/3rdparty/tommyds/tommyhashdyn.c index 75565c8d..40abee0e 100644 --- a/src/3rdparty/tommyds/tommyhashdyn.c +++ b/src/3rdparty/tommyds/tommyhashdyn.c @@ -216,6 +216,40 @@ TOMMY_API void tommy_hashdyn_foreach_arg(tommy_hashdyn* hashdyn, tommy_foreach_a } } +TOMMY_API void tommy_hashdyn_foreach_node(tommy_hashdyn* hashdyn, tommy_foreach_node_func* func) +{ + tommy_size_t bucket_max = hashdyn->bucket_max; + tommy_hashdyn_node** bucket = hashdyn->bucket; + tommy_size_t pos; + + for (pos = 0; pos < bucket_max; ++pos) { + tommy_hashdyn_node* node = bucket[pos]; + + while (node) { + tommy_hashdyn_node* next = node->next; + func(node); + node = next; + } + } +} + +TOMMY_API void tommy_hashdyn_foreach_node_arg(tommy_hashdyn* hashdyn, tommy_foreach_node_arg_func* func, void* arg) +{ + tommy_size_t bucket_max = hashdyn->bucket_max; + tommy_hashdyn_node** bucket = hashdyn->bucket; + tommy_size_t pos; + + for (pos = 0; pos < bucket_max; ++pos) { + tommy_hashdyn_node* node = bucket[pos]; + + while (node) { + tommy_hashdyn_node* next = node->next; + func(arg, node); + node = next; + } + } +} + TOMMY_API tommy_size_t tommy_hashdyn_memory_usage(tommy_hashdyn* hashdyn) { return hashdyn->bucket_max * (tommy_size_t)sizeof(hashdyn->bucket[0]) diff --git a/src/3rdparty/tommyds/tommyhashdyn.h b/src/3rdparty/tommyds/tommyhashdyn.h index caf8045f..7aa554da 100644 --- a/src/3rdparty/tommyds/tommyhashdyn.h +++ b/src/3rdparty/tommyds/tommyhashdyn.h @@ -278,6 +278,16 @@ TOMMY_API void tommy_hashdyn_foreach(tommy_hashdyn* hashdyn, tommy_foreach_func* */ TOMMY_API void tommy_hashdyn_foreach_arg(tommy_hashdyn* hashdyn, tommy_foreach_arg_func* func, void* arg); +/** + * Calls the specified function for each node in the hashtable. + */ +TOMMY_API void tommy_hashdyn_foreach_node(tommy_hashdyn* hashdyn, tommy_foreach_node_func* func); + +/** + * Calls the specified function with an argument for each node in the hashtable. + */ +TOMMY_API void tommy_hashdyn_foreach_node_arg(tommy_hashdyn* hashdyn, tommy_foreach_node_arg_func* func, void* arg); + /** * Gets the number of elements. */ diff --git a/src/3rdparty/tommyds/tommytypes.h b/src/3rdparty/tommyds/tommytypes.h index 0cb797a1..a4dfbc54 100644 --- a/src/3rdparty/tommyds/tommytypes.h +++ b/src/3rdparty/tommyds/tommytypes.h @@ -316,6 +316,19 @@ typedef void tommy_foreach_func(void* obj); */ typedef void tommy_foreach_arg_func(void* arg, void* obj); +/** + * Foreach node function. + * \param node Pointer to the node to iterate. + */ +typedef void tommy_foreach_node_func(void* node); + +/** + * Foreach node function with an argument. + * \param arg Pointer to a generic argument. + * \param node Pointer to the node to iterate. + */ +typedef void tommy_foreach_node_arg_func(void* arg, void* node); + /******************************************************************************/ /* bit hacks */ diff --git a/src/driver/fortstat.c b/src/driver/fortstat.c index 875f3be2..2b7a0683 100644 --- a/src/driver/fortstat.c +++ b/src/driver/fortstat.c @@ -188,13 +188,6 @@ fort_stat_proc_free (PFORT_STAT stat, PFORT_STAT_PROC proc) stat->proc_free = proc; } -static void -fort_stat_proc_free_data (PFORT_STAT stat, void *data) -{ - PFORT_STAT_PROC proc = (PFORT_STAT_PROC) fort_tommyhashdyn_node(data); - fort_stat_proc_free(stat, proc); -} - static PFORT_STAT_PROC fort_stat_proc_add (PFORT_STAT stat, UINT32 process_id) { @@ -268,26 +261,12 @@ fort_flow_context_remove (PFORT_STAT stat, PFORT_FLOW flow) FwpsFlowRemoveContext0(flow_id, FWPS_LAYER_OUTBOUND_TRANSPORT_V4, stat->out_transport4_id); } -static void -fort_flow_context_remove_data (PFORT_STAT stat, void *data) -{ - PFORT_FLOW flow = (PFORT_FLOW) fort_tommyhashdyn_node(data); - fort_flow_context_remove(stat, flow); -} - static void fort_flow_close (PFORT_FLOW flow) { flow->opt.proc_index = FORT_PROC_BAD_INDEX; } -static void -fort_flow_close_data (void *data) -{ - PFORT_FLOW flow = (PFORT_FLOW) fort_tommyhashdyn_node(data); - fort_flow_close(flow); -} - static PFORT_FLOW fort_flow_get (PFORT_STAT stat, UINT64 flow_id, tommy_key_t flow_hash) { @@ -391,8 +370,8 @@ fort_stat_close (PFORT_STAT stat) stat->closed = TRUE; - tommy_hashdyn_foreach_arg(&stat->flows_map, - fort_flow_context_remove_data, stat); + tommy_hashdyn_foreach_node_arg(&stat->flows_map, + fort_flow_context_remove, stat); tommy_arrayof_done(&stat->procs); tommy_hashdyn_done(&stat->procs_map); @@ -408,8 +387,8 @@ fort_stat_clear (PFORT_STAT stat) { fort_stat_proc_active_clear(stat); - tommy_hashdyn_foreach_arg(&stat->procs_map, fort_stat_proc_free_data, stat); - tommy_hashdyn_foreach(&stat->flows_map, fort_flow_close_data); + tommy_hashdyn_foreach_node_arg(&stat->procs_map, fort_stat_proc_free, stat); + tommy_hashdyn_foreach_node(&stat->flows_map, fort_flow_close); RtlZeroMemory(stat->groups, sizeof(stat->groups)); } diff --git a/src/driver/forttds.c b/src/driver/forttds.c index b07d1717..18f9dc73 100644 --- a/src/driver/forttds.c +++ b/src/driver/forttds.c @@ -53,6 +53,3 @@ fort_tommy_realloc (PVOID p, SIZE_T new_size) #include "..\3rdparty\tommyds\tommylist.c" #include "..\3rdparty\tommyds\tommyhash.c" #include "..\3rdparty\tommyds\tommyhashdyn.c" - -#define fort_tommyhashdyn_node(datap) \ - ((tommy_hashdyn_node *) ((char *) (datap) - offsetof(tommy_hashdyn_node, data)))