list - #ifndef _LIB_KERNEL_LIST_H #define...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#ifndef __LIB_KERNEL_LIST_H #define __LIB_KERNEL_LIST_H /* Doubly linked list. This implementation of a doubly linked list does not require use of dynamically allocated memory. Instead, each structure that is a potential list element must embed a struct list_elem member. All of the list functions operate on these `struct list_elem's. The list_entry macro allows conversion from a struct list_elem back to a structure object that contains it. For example, suppose there is a needed for a list of `struct foo'. `struct foo' should contain a `struct list_elem' member, like so: struct foo { struct list_elem elem; int bar; ...other members. .. }; Then a list of `struct foo' can be be declared and initialized like so: struct list foo_list; list_init (&foo_list); Iteration is a typical situation where it is necessary to convert from a struct list_elem back to its enclosing structure. Here's an example using foo_list: struct list_elem *e; for (e = list_begin (&foo_list); e != list_end (&foo_list); e = list_next (e)) { struct foo *f = list_entry (e, struct foo, elem); something with f. .. } You can find real examples of list usage throughout the source; for example, malloc.c, palloc.c, and thread.c in the threads directory all use lists. The interface for this list is inspired by the list<> template
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

list - #ifndef _LIB_KERNEL_LIST_H #define...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online