Find the answer to your Linux question:
Results 1 to 2 of 2
(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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2

    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

  2. #2
    Just Joined!
    Join Date
    Oct 2008
    Posts
    2

    Resolved

    klist operation is correct.

    When an entry is added to the list the ref count is set to 1. The iterator increments the ref count when it arrives at an entry. If the iteration breaks early, the klist_iter_exit function calls klist_del. This will decrement the ref count, but since it is still non-zero will not actually remove it from the list.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •