forked from sophgo/sophon-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmutility_list.h
75 lines (56 loc) · 2.4 KB
/
bmutility_list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//===----------------------------------------------------------------------===//
//
// Copyright (C) 2022 Sophgo Technologies Inc. All rights reserved.
//
// SOPHON-PIPELINE is licensed under the 2-Clause BSD License except for the
// third-party components.
//
//===----------------------------------------------------------------------===//
#ifndef SOPHON_PIPELINE_BMUTILITY_LIST_H
#define SOPHON_PIPELINE_BMUTILITY_LIST_H
struct ListHead {
struct ListHead *prev, *next;
};
#define INIT_LIST_HEAD(ptr) do {(ptr)->next = (ptr); (ptr)->prev = (ptr);} while (0)
#define list_for_each_next(pos, head) for (pos = (head)->next; pos != (head); pos = pos->next)
#define list_for_each_prev(pos, head) for (pos = (head)->prev; pos != (head); pos = pos->prev)
#define list_for_each_safe(pos, n, head) for (pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next)
#define LIST_HOST_ENTRY(address, type, field) ((type *)((char*)(address) - (size_t)(&((type *)0)->field)))
#define list_for_each_entry_next(pos, head, T, member) \
for (pos = LIST_HOST_ENTRY((head)->next, T, member); &pos->member != (head); \
pos = LIST_HOST_ENTRY(pos->member.next, T, member))
static __inline void __list_add(struct ListHead *newNode, struct ListHead *prev, struct ListHead *next) {
next->prev = newNode;
newNode->next = next;
newNode->prev = prev;
prev->next = newNode;
}
static __inline void __list_del(struct ListHead *prev, struct ListHead *next)
{
next->prev = prev;
prev->next = next;
}
static __inline void list_push_back(struct ListHead *newNode, struct ListHead *head) {
INIT_LIST_HEAD(newNode);
__list_add(newNode, head, head->next);
}
static __inline void list_push_front(struct ListHead *newNode, struct ListHead *head) {
INIT_LIST_HEAD(newNode);
__list_add(newNode, head->prev, head);
}
static __inline void list_del(struct ListHead *entry) {
__list_del(entry->prev, entry->next);
}
static __inline int list_empty(struct ListHead *head)
{
return head->next == head;
}
static __inline struct ListHead* list_next(struct ListHead *head) {
return head->next;
}
static __inline struct ListHead* list_prev(struct ListHead *head) {
return head->prev;
}
#define list_front(head) list_prev(head)
#define list_back(head) list_next(head)
#endif //SOPHON_PIPELINE_BMUTILITY_LIST_H