diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-04-16 11:39:59 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-04-16 12:57:15 +0800 |
commit | 7b396a45d43cc464539cc25799ddda3a27339bd8 (patch) | |
tree | cf26e66216eddc8786a1fb6f1ec3496a3edb41a0 | |
parent | 12a5c9153ce95ddde7fb14eaba9d779933a3637c (diff) | |
download | petitboot-7b396a45d43cc464539cc25799ddda3a27339bd8.zip petitboot-7b396a45d43cc464539cc25799ddda3a27339bd8.tar.gz |
lib/list: Add list_for_each_entry_safe
Add a list iterator that is safe against deletion of the current
element.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r-- | lib/list/list.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/list/list.h b/lib/list/list.h index cd9cd10..97fb615 100644 --- a/lib/list/list.h +++ b/lib/list/list.h @@ -40,6 +40,14 @@ struct list { #define list_for_each_entry_continue(_list, _pos, _member) \ for (; _pos; _pos = list_next_entry(_list, _pos, _member)) +#define list_for_each_entry_safe(_list, _pos, _tmp, _member) \ + for (_pos = container_of((_list)->head.next, typeof(*_pos), _member), \ + _tmp = container_of(_pos->_member.next, typeof(*_pos), \ + _member); \ + &_pos->_member != &(_list)->head; \ + _pos = _tmp, \ + _tmp = list_entry(_tmp->_member.next, typeof(*_pos), \ + _member, _list)) #define DEFINE_LIST(_list) struct list _list = { \ .head = { \ |