Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today! Win Great Prizes!
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > The Linux Kernel > Does klist_iter_exit delete the entry from list??

Forgot Password?
 The Linux Kernel   Compiling, theory, programming or other discussion about the linux kernel

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 10-26-2008   #1 (permalink)
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
jcrowley3 is offline  



Reply With Quote
Old 10-27-2008   #2 (permalink)
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.
jcrowley3 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
A Newbie's Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you're a complete Linux newbie and looking for a quick and easy guide to get you started this is it.
subscribe
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 03:11 PM.






© 2000 - - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.1