From 939e93787e43a3ac4355c8ee42df162aa67d2b56 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Thu, 9 Aug 2007 12:43:11 +0000 Subject: [PATCH] made linked lists invoke() method consistent to clone_*() and destroy_*() methods --- src/charon/processing/jobs/callback_job.c | 2 +- src/libstrongswan/utils/linked_list.c | 23 +++++++++++++++++++---- src/libstrongswan/utils/linked_list.h | 10 +++++++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/charon/processing/jobs/callback_job.c b/src/charon/processing/jobs/callback_job.c index 53e7caa95..6f534e0f7 100644 --- a/src/charon/processing/jobs/callback_job.c +++ b/src/charon/processing/jobs/callback_job.c @@ -130,7 +130,7 @@ static void cancel(private_callback_job_t *this) thread = this->thread; /* terminate its children */ - this->children->invoke(this->children, offsetof(callback_job_t, cancel)); + this->children->invoke_offset(this->children, offsetof(callback_job_t, cancel)); pthread_mutex_unlock(&this->mutex); /* terminate thread */ diff --git a/src/libstrongswan/utils/linked_list.c b/src/libstrongswan/utils/linked_list.c index 54fbe4432..2ba2b581e 100644 --- a/src/libstrongswan/utils/linked_list.c +++ b/src/libstrongswan/utils/linked_list.c @@ -631,9 +631,9 @@ static status_t get_last(private_linked_list_t *this, void **item) } /** - * Implementation of linked_list_t.invoke. + * Implementation of linked_list_t.invoke_offset. */ -static void invoke(private_linked_list_t *this, size_t offset) +static void invoke_offset(private_linked_list_t *this, size_t offset) { element_t *current = this->first; @@ -645,6 +645,20 @@ static void invoke(private_linked_list_t *this, size_t offset) } } +/** + * Implementation of linked_list_t.invoke_function. + */ +static void invoke_function(private_linked_list_t *this, void(*fn)(void*)) +{ + element_t *current = this->first; + + while (current) + { + fn(current->value); + current = current->next; + } +} + /** * Implementation of linked_list_t.clone_offset */ @@ -687,7 +701,7 @@ static void destroy(private_linked_list_t *this) { void *value; /* Remove all list items before destroying list */ - while (this->public.remove_first(&(this->public), &value) == SUCCESS) + while (remove_first(this, &value) == SUCCESS) { /* values are not destroyed so memory leaks are possible * if list is not empty when deleting */ @@ -789,7 +803,8 @@ linked_list_t *linked_list_create() this->public.insert_at_position = (status_t (*) (linked_list_t *,size_t, void *))insert_at_position; this->public.remove_at_position = (status_t (*) (linked_list_t *,size_t, void **))remove_at_position; this->public.get_at_position = (status_t (*) (linked_list_t *,size_t, void **))get_at_position; - this->public.invoke = (void (*)(linked_list_t*,size_t))invoke; + this->public.invoke_offset = (void (*)(linked_list_t*,size_t))invoke_offset; + this->public.invoke_function = (void (*)(linked_list_t*,void(*)(void*)))invoke_function; this->public.clone_offset = (linked_list_t * (*)(linked_list_t*,size_t))clone_offset; this->public.clone_function = (linked_list_t * (*)(linked_list_t*,void*(*)(void*)))clone_function; this->public.destroy = (void (*) (linked_list_t *))destroy; diff --git a/src/libstrongswan/utils/linked_list.h b/src/libstrongswan/utils/linked_list.h index 4f313ded6..ca6b11d0d 100644 --- a/src/libstrongswan/utils/linked_list.h +++ b/src/libstrongswan/utils/linked_list.h @@ -184,7 +184,15 @@ struct linked_list_t { * @param this calling object * @param offset offset of the method to invoke on objects */ - void (*invoke) (linked_list_t *this, size_t offset); + void (*invoke_offset) (linked_list_t *this, size_t offset); + + /** + * @brief Invoke a function on all of the contained objects. + * + * @param this calling object + * @param offset offset of the method to invoke on objects + */ + void (*invoke_function) (linked_list_t *this, void (*)(void*)); /** * @brief Clones a list and its objects using the objects' clone method.