Crinit -- Configurable Rootfs Init
|
#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | crinitList |
Macros | |
#define | container_of(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member))) |
#define | CRINIT_LIST_INIT(list) { &(list), &(list) } |
#define | crinitListEntry(entry, type, member) container_of(entry, type, member) |
#define | crinitListFirstEntry(list, type, member) crinitListEntry((list)->next, type, member) |
#define | crinitListLastEntry(list, type, member) crinitListEntry((list)->prev, type, member) |
#define | crinitListPrevEntry(entry, member) crinitListEntry((entry)->member.prev, __typeof(*(entry)), member) |
#define | crinitListNextEntry(entry, member) crinitListEntry((entry)->member.next, __typeof(*(entry)), member) |
#define | crinitListEntryIsHead(entry, list, member) (&(entry)->member == (list)) |
#define | crinitListForEachEntry(entry, list, member) |
#define | crinitListForEachEntrySafe(entry, temp, list, member) |
Typedefs | |
typedef struct crinitList | crinitList_t |
typedef int(* | crinitListCmp_t) (crinitList_t *e1, crinitList_t *e2) |
Functions | |
static void | crinitListInit (crinitList_t *list) |
static void | crinitListInsert (crinitList_t *entry, crinitList_t *prev, crinitList_t *next) |
static void | crinitListPrepend (crinitList_t *list, crinitList_t *entry) |
static void | crinitListAppend (crinitList_t *list, crinitList_t *entry) |
static void | crinitListInsertSorted (crinitList_t *list, crinitList_t *entry, crinitListCmp_t entryCmp) |
static void | crinitListDelete (crinitList_t *entry) |
static int | crinitListIsEmpty (const crinitList_t *list) |
Implementation of a doubly linked intrusive list.
Intrusive lists use a list structure containing a next pointer pointing to the next list element for singly linked list and a next and prev pointer pointing to the next and previous element for a doubly linked list. This list type gets embedded into the entry type struct which should be listed. With the help of a container_of macro the parent struct can be retrived for a given list entry. To construct a list a list head is generated, which is not embedded into the struct managed in the list. This head points to the first (head->next) and last (head-prev) entry in the list or to itself, if the list is empty. Thus iterating the list is as simple as starting at head->next and iterating through the entries with cur->next, until cur->next points to head again.
#define container_of | ( | ptr, | |
type, | |||
member | |||
) | ((type *)((char *)(ptr)-offsetof(type, member))) |
Macro to find the container struct to a given struct field.
ptr | Pointer to the field in the structure. |
type | Type of the container wrapping the field. |
member | Name of the field the pointer points to. |
#define CRINIT_LIST_INIT | ( | list | ) | { &(list), &(list) } |
Initializes a new list head by pointing the previous and next pointer to itself.
list | List to be initialized. |
#define crinitListEntry | ( | entry, | |
type, | |||
member | |||
) | container_of(entry, type, member) |
Return the struct containing this list pointer,
entry | Pointer to the list entry. |
type | Type of the containing struct. |
member | Name of the list member within the container type. |
#define crinitListEntryIsHead | ( | entry, | |
list, | |||
member | |||
) | (&(entry)->member == (list)) |
Returns wether the current container entry contains the list head.
entry | Current container entry. |
list | Pointer to the list head. |
member | Name of the list member within the container type. |
#define crinitListFirstEntry | ( | list, | |
type, | |||
member | |||
) | crinitListEntry((list)->next, type, member) |
Return the containing entry for the first list entry,
list | Pointer to the list head. |
type | Type of the containing struct. |
member | Name of the list member within the container type. |
#define crinitListForEachEntry | ( | entry, | |
list, | |||
member | |||
) |
Iterates over all entries in the list.
entry | Current container entry. |
list | Pointer to the list head. |
member | Name of the list member within the container type. |
#define crinitListForEachEntrySafe | ( | entry, | |
temp, | |||
list, | |||
member | |||
) |
Safely iterates over all entries in the list.
This macro additionally keeps track of the next entry of the current entry, so the loop won't break if the current entry gets removed from the list.
entry | Current container entry. |
temp | Temporary pointer, pointing to the next entry of the current container entry. |
list | Pointer to the list head. |
member | Name of the list member within the container type. |
#define crinitListLastEntry | ( | list, | |
type, | |||
member | |||
) | crinitListEntry((list)->prev, type, member) |
Return the containing entry for the last list entry,
list | Pointer to the list head. |
type | Type of the containing struct. |
member | Name of the list member within the container type. |
#define crinitListNextEntry | ( | entry, | |
member | |||
) | crinitListEntry((entry)->member.next, __typeof(*(entry)), member) |
Return the next containing entry for the current entry,
entry | Current container entry. |
member | Name of the list member within the container type. |
#define crinitListPrevEntry | ( | entry, | |
member | |||
) | crinitListEntry((entry)->member.prev, __typeof(*(entry)), member) |
Return the previous containing entry for the current entry,
entry | Current container entry. |
member | Name of the list member within the container type. |
typedef struct crinitList crinitList_t |
Simple intrusive list struct.
typedef int(* crinitListCmp_t) (crinitList_t *e1, crinitList_t *e2) |
Type for a list entry compare function.
The comparison function shall return a value > 0, if the container type of e2 is larger than the one of e2, a value < 0 if less than the one of e2 and 0 if they are equal.
|
inlinestatic |
Appends a new entry at the end of the list.
list | Pointer to the list. |
entry | Entry to be appended. |
|
inlinestatic |
Deletes the current entry from the list.
Removes the entry from the list by updating the next pointer of the previous and the prev pointer of the next entry, while setting the next and prev pointers of the entry itself to null. However this will cause a stack error if either entry, entry->next or entry->prev is NULL.
entry | Entry to be removed from the list. |
|
inlinestatic |
Initializes a new list head by pointing the previous and next pointer to itself.
list | Pointer to list to be initialized. |
|
inlinestatic |
Insert a new list entry.
entry | Entry to be inserted. |
prev | Entry to be inserted after. |
next | Entry to be inserted before. |
|
inlinestatic |
Insert sorted based on a simple comparison callback.
list | List to insert the entry into. |
entry | Entry to be inserted. |
entryCmp | Compare callback. |
|
inlinestatic |
Returns wether the list is empty or not.
Checks if the list is empty by checking if the next pointer of the list points to the list itself.
list | The list to be checked. |
|
inlinestatic |
Insert a new entry at the beginning of the list.
list | Pointer to the list. |
entry | Entry to be appended. |