- linux features standard implementations for various types and functions:
- linked lists
- circular, double linked list (linux/list.h)
- klists, more sophisticated list with locking and ref counting (linux/klist.h)
- kfifos (linux/kfifo.h)
- string functions
- bit and bitmap operations
- (commandline) parsing
- crc functions
- ...
make htmldocs
firefox Documentation/DocBook/index.html
-> kernel api
API: linked lists
type:
struct list_head {
struct list_head *next, *prev;
};
Initalize head pointer:
struct list_head mempool;
INIT_LIST_HEAD(&mempool); /* at runtime or ... */
LIST_HEAD(mempool); /* at compile time */
Embedd struct list_head
in list element:
struct mem_chunk {
unsigned char *ptr;
int len;
struct list_head list;
}
add element:
struct mem_chunk mc;
mc.ptr = this;
mc.len = 128;
list_add(&mc.list, &mempool);
remove element:
struct list_head myelement = list_del(&mempool.next);
find superstructure:
mc = list_entry(myelement, struct mem_chunk, list);
Functions:
see
kernel-api documentation and
include/list.h