format using clang-format to formate code
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
* @link https://njusecourse.feishu.cn/wiki/I8vkw2zkwiEInUkujTJc7zzOnwf
|
||||
* @link https://kernelnewlbies.org/FAQ/LinkedLists
|
||||
* @link https://lwn.net/Articles/887097/
|
||||
* @link https://liuluheng.github.io/wiki/public_html/Embedded-System/kernel/list-and-hlist.html
|
||||
* @link
|
||||
* https://liuluheng.github.io/wiki/public_html/Embedded-System/kernel/list-and-hlist.html
|
||||
*/
|
||||
|
||||
#ifndef __KLLIST_H__
|
||||
@@ -18,13 +19,17 @@
|
||||
// Magic: https://radek.io/posts/magical-container_of-macro/
|
||||
// StackOverflow: https://stackoverflow.com/q/15832301/1833118
|
||||
#ifdef __GNUC__
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
#define container_of(ptr, type, member) \
|
||||
({ \
|
||||
const typeof(((type *)0)->member) *__mptr = (ptr); \
|
||||
(type *)((char *)__mptr - offsetof(type, member)); \
|
||||
})
|
||||
#else
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const void *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
#define container_of(ptr, type, member) \
|
||||
({ \
|
||||
const void *__mptr = (ptr); \
|
||||
(type *)((char *)__mptr - offsetof(type, member)); \
|
||||
})
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -37,26 +42,25 @@ struct list_head {
|
||||
|
||||
/**
|
||||
* list init
|
||||
* @example
|
||||
* @example
|
||||
* 1. struct list_head your_list = LIST_HEAD_INIT(your_list);
|
||||
* 2. struct list_head your_list; INIT_LIST_HEAD(&your_list);
|
||||
* 3. LIST_HEAD(your_list); => struct your_list = { &(your_list), &(your_list) };
|
||||
* 3. LIST_HEAD(your_list); => struct your_list = { &(your_list), &(your_list)
|
||||
* };
|
||||
*/
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
#define LIST_HEAD_INIT(name) {&(name), &(name)}
|
||||
static inline void INIT_LIST_HEAD(struct list_head *list) {
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
/**
|
||||
* list add
|
||||
*/
|
||||
|
||||
static inline void __list_add(struct list_head *newl,
|
||||
struct list_head *prev,
|
||||
static inline void __list_add(struct list_head *newl, struct list_head *prev,
|
||||
struct list_head *next) {
|
||||
next->prev = newl;
|
||||
newl->next = next;
|
||||
@@ -68,7 +72,8 @@ static inline void list_add(struct list_head *newl, struct list_head *head) {
|
||||
__list_add(newl, head, head->next);
|
||||
}
|
||||
|
||||
static inline void list_add_tail(struct list_head *newl, struct list_head *head) {
|
||||
static inline void list_add_tail(struct list_head *newl,
|
||||
struct list_head *head) {
|
||||
__list_add(newl, head->prev, head);
|
||||
}
|
||||
|
||||
@@ -76,7 +81,7 @@ static inline void list_add_tail(struct list_head *newl, struct list_head *head)
|
||||
* list delete
|
||||
*/
|
||||
|
||||
static inline void __list_del(struct list_head * prev, struct list_head * next) {
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next) {
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
@@ -84,7 +89,7 @@ static inline void __list_del(struct list_head * prev, struct list_head * next)
|
||||
static inline void list_del(struct list_head *entry) {
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = NULL;
|
||||
entry->prev = NULL;
|
||||
entry->prev = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,8 +97,9 @@ static inline void list_del(struct list_head *entry) {
|
||||
* @list: the entry to test
|
||||
* @head: the head of the list
|
||||
*/
|
||||
static inline int list_is_first(const struct list_head *list, const struct list_head *head) {
|
||||
return list->prev == head;
|
||||
static inline int list_is_first(const struct list_head *list,
|
||||
const struct list_head *head) {
|
||||
return list->prev == head;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,8 +107,9 @@ static inline int list_is_first(const struct list_head *list, const struct list_
|
||||
* @list: the entry to test
|
||||
* @head: the head of the list
|
||||
*/
|
||||
static inline int list_is_last(const struct list_head *list, const struct list_head *head) {
|
||||
return list->next == head;
|
||||
static inline int list_is_last(const struct list_head *list,
|
||||
const struct list_head *head) {
|
||||
return list->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,8 +117,9 @@ static inline int list_is_last(const struct list_head *list, const struct list_h
|
||||
* @list: the entry to test
|
||||
* @head: the head of the list
|
||||
*/
|
||||
static inline int list_is_head(const struct list_head *list, const struct list_head *head) {
|
||||
return list == head;
|
||||
static inline int list_is_head(const struct list_head *list,
|
||||
const struct list_head *head) {
|
||||
return list == head;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +127,7 @@ static inline int list_is_head(const struct list_head *list, const struct list_h
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(const struct list_head *head) {
|
||||
return head->next == head;
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,16 +135,16 @@ static inline int list_empty(const struct list_head *head) {
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; !list_is_head(pos, (head)); pos = pos->next)
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; !list_is_head(pos, (head)); pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; !list_is_head(pos, (head)); pos = pos->prev)
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; !list_is_head(pos, (head)); pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list sort
|
||||
@@ -146,8 +154,8 @@ static inline int list_empty(const struct list_head *head) {
|
||||
*/
|
||||
|
||||
#ifdef HAVE_KLIST_SORT
|
||||
typedef int (*list_cmp_func_t)(void *,
|
||||
const struct list_head *, const struct list_head *);
|
||||
typedef int (*list_cmp_func_t)(void *, const struct list_head *,
|
||||
const struct list_head *);
|
||||
static void list_sort(void *priv, struct list_head *head, list_cmp_func_t cmp);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user