Commit 098c5436 098c54364e0fd5ed46be0f2303bc1286c15bfde6 by Sam Roberts

New function: list_do(), calls a function on each item in the list.

1 parent 299e098a
......@@ -44,6 +44,11 @@ extern int list_count __P ((list_t, size_t *pcount));
extern int list_remove __P ((list_t, void *item));
extern int list_get __P ((list_t, size_t _index, void **pitem));
typedef int list_action_t __P ((void* item, void* cbdata));
extern int list_do __P ((list_t list, list_action_t * action, void *cbdata));
#ifdef __cplusplus
}
#endif
......
......@@ -179,3 +179,21 @@ list_get (list_t list, size_t indx, void **pitem)
monitor_unlock (list->monitor);
return status;
}
int
list_do (list_t list, list_action_t * action, void *cbdata)
{
struct list_data *current;
int status = 0;
if (list == NULL || action == NULL)
return EINVAL;
monitor_rdlock (list->monitor);
for (current = list->head.next; current != &(list->head);
current = current->next)
{
if ((status = action (current->item, cbdata)))
break;
}
monitor_unlock (list->monitor);
return status;
}
......