changed enumerator implementation to handle reentrant code
This commit is contained in:
@@ -149,9 +149,9 @@ struct private_enumerator_t {
|
|||||||
enumerator_t enumerator;
|
enumerator_t enumerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* next item to enumerate
|
* associated linked list
|
||||||
*/
|
*/
|
||||||
element_t *next;
|
private_linked_list_t *list;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* current item
|
* current item
|
||||||
@@ -164,13 +164,23 @@ struct private_enumerator_t {
|
|||||||
*/
|
*/
|
||||||
static bool enumerate(private_enumerator_t *this, void **item)
|
static bool enumerate(private_enumerator_t *this, void **item)
|
||||||
{
|
{
|
||||||
if (this->next == NULL)
|
if (!this->current)
|
||||||
{
|
{
|
||||||
return FALSE;
|
if (!this->list->first)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
this->current = this->list->first;
|
||||||
}
|
}
|
||||||
*item = this->next->value;
|
else
|
||||||
this->current = this->next;
|
{
|
||||||
this->next = this->next->next;
|
if (!this->current->next)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
this->current = this->current->next;
|
||||||
|
}
|
||||||
|
*item = this->current->value;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +193,7 @@ static enumerator_t* create_enumerator(private_linked_list_t *this)
|
|||||||
|
|
||||||
enumerator->enumerator.enumerate = (void*)enumerate;
|
enumerator->enumerator.enumerate = (void*)enumerate;
|
||||||
enumerator->enumerator.destroy = (void*)free;
|
enumerator->enumerator.destroy = (void*)free;
|
||||||
enumerator->next = this->first;
|
enumerator->list = this;
|
||||||
enumerator->current = NULL;
|
enumerator->current = NULL;
|
||||||
|
|
||||||
return &enumerator->enumerator;
|
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)
|
static void remove_at(private_linked_list_t *this, private_enumerator_t *enumerator)
|
||||||
{
|
{
|
||||||
|
element_t *current;
|
||||||
|
|
||||||
if (enumerator->current)
|
if (enumerator->current)
|
||||||
{
|
{
|
||||||
remove_element(this, enumerator->current);
|
current = enumerator->current;
|
||||||
enumerator->current = NULL;
|
enumerator->current = current->previous;
|
||||||
enumerator->next = this->first;
|
remove_element(this, current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user