mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-02 17:16:36 +00:00
Update list implementation
This commit is contained in:
parent
7b9be8369e
commit
9d421226a7
2
jni/su
2
jni/su
@ -1 +1 @@
|
||||
Subproject commit 1bbf96a0a7a942798df58883a376b8024d0fae7f
|
||||
Subproject commit 9dab3bc8ab28792993711f0a2450f9332b172687
|
@ -24,15 +24,19 @@ void list_insert_end(struct list_head *head, struct list_head *node) {
|
||||
list_insert(head->prev, node);
|
||||
}
|
||||
|
||||
void list_pop(struct list_head *pos) {
|
||||
struct list_head *list_pop(struct list_head *pos) {
|
||||
struct list_head *ret;
|
||||
ret = pos->prev;
|
||||
// Maintain the list
|
||||
pos->prev->next = pos->next;
|
||||
pos->next->prev = pos->prev;
|
||||
// Remove references
|
||||
pos->next = pos;
|
||||
pos->prev = pos;
|
||||
// Return the previous node in the list
|
||||
return ret;
|
||||
}
|
||||
|
||||
void list_pop_end(struct list_head *head) {
|
||||
struct list_head *list_pop_end(struct list_head *head) {
|
||||
return list_pop(head->prev);
|
||||
}
|
||||
|
@ -14,17 +14,30 @@ struct list_head {
|
||||
void init_list_head(struct list_head *head);
|
||||
void list_insert(struct list_head *pos, struct list_head *node);
|
||||
void list_insert_end(struct list_head *head, struct list_head *node);
|
||||
void list_pop(struct list_head *pos);
|
||||
void list_pop_end(struct list_head *head);
|
||||
struct list_head *list_pop(struct list_head *pos);
|
||||
struct list_head *list_pop_end(struct list_head *head);
|
||||
|
||||
#define list_entry(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
#define list_entry(pos, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (pos); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
#define list_for_each(ptr, head, type, member) \
|
||||
ptr = list_entry((head)->next, type, member); \
|
||||
for (struct list_head *__ = (head)->next; __ != (head); __ = __->next, ptr = list_entry(__, type, member))
|
||||
|
||||
#define list_for_each_r(pos, head) \
|
||||
for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
||||
#define list_for_each_r(ptr, head, type, member) \
|
||||
ptr = list_entry((head)->prev, type, member); \
|
||||
for (struct list_head *__ = (head)->prev; __ != (head); __ = __->prev, ptr = list_entry(__, type, member))
|
||||
|
||||
#endif
|
||||
#define list_destory(head, type, member, func) ({ \
|
||||
struct list_head *node = head->next; \
|
||||
while(node != head) { \
|
||||
node = node->next; \
|
||||
if (func) func(list_entry(node->prev, line_list, pos)); \
|
||||
free(list_entry(node->prev, line_list, pos)); \
|
||||
} \
|
||||
head->next = head; \
|
||||
head->prev = head; \
|
||||
})
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user