Line | Count | Source |
1 | | /* |
2 | | * Linux klist like system |
3 | | * |
4 | | * Copyright (c) 2016-2017 Fabrice Bellard |
5 | | * |
6 | | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | | * of this software and associated documentation files (the "Software"), to deal |
8 | | * in the Software without restriction, including without limitation the rights |
9 | | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | | * copies of the Software, and to permit persons to whom the Software is |
11 | | * furnished to do so, subject to the following conditions: |
12 | | * |
13 | | * The above copyright notice and this permission notice shall be included in |
14 | | * all copies or substantial portions of the Software. |
15 | | * |
16 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | | * THE SOFTWARE. |
23 | | */ |
24 | | #ifndef LIST_H |
25 | | #define LIST_H |
26 | | |
27 | | #ifndef NULL |
28 | | #include <stddef.h> |
29 | | #endif |
30 | | |
31 | | struct list_head { |
32 | | struct list_head *prev; |
33 | | struct list_head *next; |
34 | | }; |
35 | | |
36 | | #define LIST_HEAD_INIT(el) { &(el), &(el) } |
37 | | |
38 | | /* return the pointer of type 'type *' containing 'el' as field 'member' */ |
39 | 79.7k | #define list_entry(el, type, member) container_of(el, type, member) |
40 | | |
41 | | static inline void init_list_head(struct list_head *head) |
42 | 828 | { |
43 | 828 | head->prev = head; |
44 | 828 | head->next = head; |
45 | 828 | } Line | Count | Source | 42 | 680 | { | 43 | 680 | head->prev = head; | 44 | 680 | head->next = head; | 45 | 680 | } |
quickjs-libc.c:init_list_head Line | Count | Source | 42 | 148 | { | 43 | 148 | head->prev = head; | 44 | 148 | head->next = head; | 45 | 148 | } |
|
46 | | |
47 | | /* insert 'el' between 'prev' and 'next' */ |
48 | | static inline void __list_add(struct list_head *el, |
49 | | struct list_head *prev, struct list_head *next) |
50 | 86.3k | { |
51 | 86.3k | prev->next = el; |
52 | 86.3k | el->prev = prev; |
53 | 86.3k | el->next = next; |
54 | 86.3k | next->prev = el; |
55 | 86.3k | } Line | Count | Source | 50 | 86.3k | { | 51 | 86.3k | prev->next = el; | 52 | 86.3k | el->prev = prev; | 53 | 86.3k | el->next = next; | 54 | 86.3k | next->prev = el; | 55 | 86.3k | } |
Unexecuted instantiation: quickjs-libc.c:__list_add |
56 | | |
57 | | /* add 'el' at the head of the list 'head' (= after element head) */ |
58 | | static inline void list_add(struct list_head *el, struct list_head *head) |
59 | 343 | { |
60 | 343 | __list_add(el, head, head->next); |
61 | 343 | } Line | Count | Source | 59 | 343 | { | 60 | 343 | __list_add(el, head, head->next); | 61 | 343 | } |
Unexecuted instantiation: quickjs-libc.c:list_add |
62 | | |
63 | | /* add 'el' at the end of the list 'head' (= before element head) */ |
64 | | static inline void list_add_tail(struct list_head *el, struct list_head *head) |
65 | 86.0k | { |
66 | 86.0k | __list_add(el, head->prev, head); |
67 | 86.0k | } Line | Count | Source | 65 | 86.0k | { | 66 | 86.0k | __list_add(el, head->prev, head); | 67 | 86.0k | } |
Unexecuted instantiation: quickjs-libc.c:list_add_tail |
68 | | |
69 | | static inline void list_del(struct list_head *el) |
70 | 80.6k | { |
71 | 80.6k | struct list_head *prev, *next; |
72 | 80.6k | prev = el->prev; |
73 | 80.6k | next = el->next; |
74 | 80.6k | prev->next = next; |
75 | 80.6k | next->prev = prev; |
76 | 80.6k | el->prev = NULL; /* fail safe */ |
77 | 80.6k | el->next = NULL; /* fail safe */ |
78 | 80.6k | } Line | Count | Source | 70 | 80.6k | { | 71 | 80.6k | struct list_head *prev, *next; | 72 | 80.6k | prev = el->prev; | 73 | 80.6k | next = el->next; | 74 | 80.6k | prev->next = next; | 75 | 80.6k | next->prev = prev; | 76 | 80.6k | el->prev = NULL; /* fail safe */ | 77 | 80.6k | el->next = NULL; /* fail safe */ | 78 | 80.6k | } |
Unexecuted instantiation: quickjs-libc.c:list_del |
79 | | |
80 | | static inline int list_empty(struct list_head *el) |
81 | 158 | { |
82 | 158 | return el->next == el; |
83 | 158 | } Line | Count | Source | 81 | 113 | { | 82 | 113 | return el->next == el; | 83 | 113 | } |
quickjs-libc.c:list_empty Line | Count | Source | 81 | 45 | { | 82 | 45 | return el->next == el; | 83 | 45 | } |
|
84 | | |
85 | | #define list_for_each(el, head) \ |
86 | 30.6k | for(el = (head)->next; el != (head); el = el->next) |
87 | | |
88 | | #define list_for_each_safe(el, el1, head) \ |
89 | 36.0k | for(el = (head)->next, el1 = el->next; el != (head); \ |
90 | 35.3k | el = el1, el1 = el->next) |
91 | | |
92 | | #define list_for_each_prev(el, head) \ |
93 | | for(el = (head)->prev; el != (head); el = el->prev) |
94 | | |
95 | | #define list_for_each_prev_safe(el, el1, head) \ |
96 | | for(el = (head)->prev, el1 = el->prev; el != (head); \ |
97 | | el = el1, el1 = el->prev) |
98 | | |
99 | | #endif /* LIST_H */ |