diff options
author | Martin Willi <martin@strongswan.org> | 2008-04-01 06:51:55 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2008-04-01 06:51:55 +0000 |
commit | e411f94d4416f861b0935846fce84d9319787f1c (patch) | |
tree | 0442a5db221276953e19124840f3ac1bd78deb2e /src | |
parent | c096472605aa264af62e8b1359b4fa2662f33a89 (diff) | |
download | strongswan-e411f94d4416f861b0935846fce84d9319787f1c.tar.bz2 strongswan-e411f94d4416f861b0935846fce84d9319787f1c.tar.xz |
changed enumerator implementation to handle reentrant code
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/utils/linked_list.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/libstrongswan/utils/linked_list.c b/src/libstrongswan/utils/linked_list.c index ee46b2b8c..cab6d8635 100644 --- a/src/libstrongswan/utils/linked_list.c +++ b/src/libstrongswan/utils/linked_list.c @@ -149,9 +149,9 @@ struct private_enumerator_t { enumerator_t enumerator; /** - * next item to enumerate + * associated linked list */ - element_t *next; + private_linked_list_t *list; /** * current item @@ -164,13 +164,23 @@ struct private_enumerator_t { */ static bool enumerate(private_enumerator_t *this, void **item) { - if (this->next == NULL) + if (!this->current) + { + if (!this->list->first) + { + return FALSE; + } + this->current = this->list->first; + } + else { - return FALSE; + if (!this->current->next) + { + return FALSE; + } + this->current = this->current->next; } - *item = this->next->value; - this->current = this->next; - this->next = this->next->next; + *item = this->current->value; return TRUE; } @@ -183,7 +193,7 @@ static enumerator_t* create_enumerator(private_linked_list_t *this) enumerator->enumerator.enumerate = (void*)enumerate; enumerator->enumerator.destroy = (void*)free; - enumerator->next = this->first; + enumerator->list = this; enumerator->current = NULL; return &enumerator->enumerator; @@ -602,11 +612,13 @@ static int remove(private_linked_list_t *this, void *item, */ static void remove_at(private_linked_list_t *this, private_enumerator_t *enumerator) { + element_t *current; + if (enumerator->current) { - remove_element(this, enumerator->current); - enumerator->current = NULL; - enumerator->next = this->first; + current = enumerator->current; + enumerator->current = current->previous; + remove_element(this, current); } } |