Re: list_entry()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



These are the functions that enable generic linked list implementation.
list_entry will return a pointer to the structure which encapsulates the list_head pointer passed as an arg. In short, it extracts the address of the structure which encapsulates a fied of it.
As an example, here is a simple code snippet
struct mylist {
     int num;
     struct list_head p;
};
 
You can use list_entry(ty,struct mylist,p);
where ty is actually pointer to list_head(address of the member p which is encapsulated in the structure). This functions allow for a generic list implementation since all list manipulation can be done via list_head pointers.
list_for_each allow you to iterate over the list taking a pointer(list_head) to the head of the list and
the pointer of list_head which hold each member as you iterate through the list. As an example(continuing with prev snippets),
/* Iterates through the list and the prints the data in it. */
struct mylist *myl;
struct list_head *entry;
list_for_each(entry,&headnode){
myl = list_head(entry,struct mylist,p);
printk("\n %d",myl->num);
}
 
Thayumanavar

 
On 9/2/05, raja <vnagaraju@xxxxxxxxxxxx> wrote:
  Hi,
       Will you please help me.What are the functions
list_entry(),list_for_each() refers to?And wht are the arguments that
are to be passed to?

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux