Insert the new node right before the second parameter (useful for implementing queues). We have just created our linked list and now we are ready to loop over it. Void list_add_tail(struct list_head *new, struct list_head *head) Note that it accept two parameter and it will insert the first parameter just after the second (if we pass as second parameter the head we are actually implementing a stack). The list_add function relies on the internal _list_add function defined above. Static inline void list_add(struct list_head *new, struct list_head *head) * Insert a new entry after the specified head. Static inline void _list_add(struct list_head *new, * This is only for internal list manipulation where we know * Insert a new entry between two known consecutive entries. Let's add some points (representing the function ) to our freshly created list: For example we will use the list_add function provided that add the new node right after the head of the list. Out list is now ready to be filled out with "nodes" that can be added to the list using different functions (to the front, or tail for instance, useful for using the list for implementing other data structures as stacks or queues). Note that is clear from here that one can also declare a point2D as start point and initialize directly its list_head field by means of the LIST_HEAD_INIT macro. That simply create a single node linked list. Struct list_head name =LIST_HEAD_INIT(name) This could be accomplished using the macro The first thing to do in order to utilized it is to create a list head, a start point for the data structure. With that in mind our kernel point2D list would be to use them one has just to add a field of type struct list_head inside the structure we want the list to be made of. To overcome this problem list in the kernel are implemented s.t. The drawback of this approach is that in order to manipulate that list one have to write type specific code for adding/removing nodes in/from the list. The links to the previous and subsequent element of the list. The canonical implementation of a C's linked list consists of a structure and two (for a doubly linked) recursive pointer fields to the structure itself. From canonical list to Linux kernel linked list It is a very smart written piece of code that is worth to take a look at as it is an opportunity to improve C programming skills and at the same time to see an "unconventional" implementation for a common data structure. We will briefly look in this article at the list.h file (in the linux source tree under /usr/src/linux-headers-`uname -r`/include/) that provides macros and function for utilizing a doubly linked circular list. Kernel's developers decided to provide a unique set of API for using these kind of software machineries. Linux Kernel especially in the past years was plenty of different and replicated implementation of generic data structures such as linked lists, stacks and queues. Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /customers/b/f/9//httpd.www/wp-content/plugins/latex/latex.php on line 48 Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /customers/b/f/9//httpd.www/wp-content/plugins/latex/latex.php on line 47
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |