Does klist_iter_exit delete the entry from list??
(Sorry if this is a double-post -- don't know what happened to the first one.)
As I read klist.c, calling klist_iter_exit to close an iteration will delete the current entry (if any) from the list.
Am I reading this correctly? Is this the intended result?
Psuedo-code example: Assume that you have a list of devices (or something similar) and need to look up the device with ID = x. The code could be something like this:
struct device *find_device(int ID){
struct klist_iter iterator;
struct klist_node *node;
struct device *dev;
klist_iter_init(&theDriverList);
while((node=klist_next(&iterator))!=NULL){
dev = (node coerced to device *)..
if(dev.ID==x){ // Found the one you wanted
klist_iter_exit(&iterator); // This does a KLIST_DEL!!!
return dev;
}
}
klist_iter_exit(&iterator);
return null;
}
So this form of the code would not only "look up" the desired entry, but has the side-effect of removing it from the list??? Is this true?
I understand that it would be possible to set the 'dev' pointer when we find the desired entry, and then just let the iteration continue until it finishes the list. Then the klist_iter_exit is OK. But if the list is potentially very long, this seems like a waste of processor resource.
Thanks for any help or suggestions.
John