-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
list: add macro LIST_FOREACH_SAFE #1197
Conversation
…linked list traversal
The preferred solution for deleting list elements while iterating is currently: struct le *le = list_head(list);
while (le)
{
struct object *obj = le->data;
le = le->next;
list_unlink(&obj->le);
} |
Your solution is: struct le *le;
struct le *n;
LIST_FOREACH_SAFE(list, le, n)
{
struct object *obj = le->data;
list_unlink(&obj->le);
} This needs a variable more and is less efficient, since it double checks NULL (next and current). |
Thank you for your reply.
|
I tried to use it, but it didn't work properly.
|
Try this one: le = list_head(&turndp()->rm_map);
while (le)
{
struct udp_socks *uks = list_ledata(le);
le = le->next;
if (thrd_id == uks->thrd_id) {
udp_thread_detach(uks->rel_us);
udp_thread_detach(uks->rsv_us);
list_unlink(&uks->le);
mem_deref(uks);
}
}
The original pointer is not modified, only the reference pointer is set to the next element and should not be used after this (before next round). |
Thank you for your reply. I tried to use it. it is ok. tks |
support modification during linked list traversal.
referring to the implementation of the Linux kernel "list_for_each_safe(pos, n, head)"