Changeset 00b7fc8 in mainline
- Timestamp:
- 2019-02-01T22:32:38Z (6 years ago)
- Parents:
- f959a20f
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 21:46:05)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 22:32:38)
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskdump/fibrildump.c
rf959a20f r00b7fc8 107 107 return EIO; 108 108 109 addr = (uintptr_t) link. next;109 addr = (uintptr_t) link.__adt_link_next; 110 110 if (addr == fibril_list_addr) 111 111 break; -
uspace/lib/c/generic/adt/list.c
rf959a20f r00b7fc8 55 55 bool list_member(const link_t *link, const list_t *list) 56 56 { 57 bool found = false;58 link_t *hlp = list->head.next;57 if (list_empty(list)) 58 return false; 59 59 60 while (hlp != &list->head) {61 if (hlp == link) { 62 found = true;63 break;64 }65 hlp = hlp-> next;60 link_t *hlp = list->__adt_list_head.__adt_link_next; 61 62 while (hlp != &list->__adt_list_head) { 63 if (hlp == link) 64 return true; 65 hlp = hlp->__adt_link_next; 66 66 } 67 67 68 return f ound;68 return false; 69 69 } 70 70 … … 83 83 84 84 /* Attach list to destination. */ 85 list-> head.next->prev = pos;86 list-> head.prev->next = pos->next;85 list->__adt_list_head.__adt_link_next->__adt_link_prev = pos; 86 list->__adt_list_head.__adt_link_prev->__adt_link_next = pos->__adt_link_next; 87 87 88 88 /* Link destination list to the added list. */ 89 pos-> next->prev = list->head.prev;90 pos-> next = list->head.next;89 pos->__adt_link_next->__adt_link_prev = list->__adt_list_head.__adt_link_prev; 90 pos->__adt_link_next = list->__adt_list_head.__adt_link_next; 91 91 92 92 list_initialize(list); -
uspace/lib/c/include/adt/list.h
rf959a20f r00b7fc8 44 44 45 45 /** Doubly linked list link. */ 46 typedef struct link {47 struct link *prev; /**< Pointer to the previous item in the list. */48 struct link *next; /**< Pointer to the next item in the list. */46 typedef struct __adt_link { 47 struct __adt_link *__adt_link_prev; /**< Pointer to the previous item in the list. */ 48 struct __adt_link *__adt_link_next; /**< Pointer to the next item in the list. */ 49 49 } link_t; 50 50 51 51 /** Doubly linked list. */ 52 typedef struct list{53 link_t head; /**< List head. Does not have any data. */52 typedef struct { 53 link_t __adt_list_head; /**< List head. Does not have any data. */ 54 54 } list_t; 55 55 … … 83 83 #define LIST_INITIALIZER(name) \ 84 84 { \ 85 . head = { \86 . prev = &(name).head, \87 . next = &(name).head \85 .__adt_list_head = { \ 86 .__adt_link_prev = &(name).__adt_list_head, \ 87 .__adt_link_next = &(name).__adt_list_head \ 88 88 } \ 89 89 } … … 92 92 ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member)))) 93 93 94 #define list_foreach_internal(list, member, itype, iterator, next, link) \ 95 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 96 for (link_t *link = (list).__adt_list_head.next; \ 97 iterator = list_get_instance(link, itype, member), \ 98 link != &(list).__adt_list_head; link = link->next) 99 100 #define __ADT_LIST_CONCAT(a, b) __ADT_LIST_CONCAT1(a, b) 101 #define __ADT_LIST_CONCAT1(a, b) a##b 102 94 103 #define list_foreach(list, member, itype, iterator) \ 95 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 96 for (link_t *_link = (list).head.next; \ 97 iterator = list_get_instance(_link, itype, member), \ 98 _link != &(list).head; _link = _link->next) 104 list_foreach_internal(list, member, itype, iterator, __adt_link_next, __ADT_LIST_CONCAT(__tmp_link_, __COUNTER__)) 99 105 100 106 #define list_foreach_rev(list, member, itype, iterator) \ 101 for (itype *iterator = NULL; iterator == NULL; iterator = (itype *) 1) \ 102 for (link_t *_link = (list).head.prev; \ 103 iterator = list_get_instance(_link, itype, member), \ 104 _link != &(list).head; _link = _link->prev) 107 list_foreach_internal(list, member, itype, iterator, __adt_link_prev, __ADT_LIST_CONCAT(__tmp_link_, __COUNTER__)) 105 108 106 109 /** Unlike list_foreach(), allows removing items while traversing a list. … … 130 133 */ 131 134 #define list_foreach_safe(list, iterator, next_iter) \ 132 for (link_t *iterator = (list). head.next, \133 *next_iter = iterator-> next; \134 iterator != &(list). head; \135 iterator = next_iter, next_iter = iterator-> next)135 for (link_t *iterator = (list).__adt_list_head.__adt_link_next, \ 136 *next_iter = iterator->__adt_link_next; \ 137 iterator != &(list).__adt_list_head; \ 138 iterator = next_iter, next_iter = iterator->__adt_link_next) 136 139 137 140 #define assert_link_not_used(link) \ … … 141 144 static inline bool link_in_use(const link_t *link) 142 145 { 143 return link-> prev != NULL && link->next != NULL;146 return link->__adt_link_prev != NULL && link->__adt_link_next != NULL; 144 147 } 145 148 … … 153 156 NO_TRACE static inline void link_initialize(link_t *link) 154 157 { 155 link->prev = NULL; 156 link->next = NULL; 158 assert(link); 159 link->__adt_link_prev = NULL; 160 link->__adt_link_next = NULL; 157 161 } 158 162 … … 166 170 NO_TRACE static inline void list_initialize(list_t *list) 167 171 { 168 list->head.prev = &list->head; 169 list->head.next = &list->head; 172 assert(list); 173 list->__adt_list_head.__adt_link_prev = &list->__adt_list_head; 174 list->__adt_list_head.__adt_link_next = &list->__adt_list_head; 170 175 } 171 176 … … 175 180 static inline void list_insert_before(link_t *lnew, link_t *lold) 176 181 { 177 lnew->next = lold; 178 lnew->prev = lold->prev; 179 lold->prev->next = lnew; 180 lold->prev = lnew; 182 assert(lnew); 183 assert(lold); 184 lnew->__adt_link_next = lold; 185 lnew->__adt_link_prev = lold->__adt_link_prev; 186 lold->__adt_link_prev->__adt_link_next = lnew; 187 lold->__adt_link_prev = lnew; 181 188 } 182 189 … … 186 193 static inline void list_insert_after(link_t *lnew, link_t *lold) 187 194 { 188 lnew->prev = lold; 189 lnew->next = lold->next; 190 lold->next->prev = lnew; 191 lold->next = lnew; 195 assert(lnew); 196 assert(lold); 197 lnew->__adt_link_prev = lold; 198 lnew->__adt_link_next = lold->__adt_link_next; 199 lold->__adt_link_next->__adt_link_prev = lnew; 200 lold->__adt_link_next = lnew; 192 201 } 193 202 … … 202 211 NO_TRACE static inline void list_prepend(link_t *link, list_t *list) 203 212 { 204 list_insert_after(link, &list-> head);213 list_insert_after(link, &list->__adt_list_head); 205 214 } 206 215 … … 215 224 NO_TRACE static inline void list_append(link_t *link, list_t *list) 216 225 { 217 list_insert_before(link, &list-> head);226 list_insert_before(link, &list->__adt_list_head); 218 227 } 219 228 … … 228 237 NO_TRACE static inline void list_remove(link_t *link) 229 238 { 230 if ((link-> prev != NULL) && (link->next != NULL)) {231 link-> next->prev = link->prev;232 link-> prev->next = link->next;239 if ((link->__adt_link_prev != NULL) && (link->__adt_link_next != NULL)) { 240 link->__adt_link_next->__adt_link_prev = link->__adt_link_prev; 241 link->__adt_link_prev->__adt_link_next = link->__adt_link_next; 233 242 } 234 243 … … 245 254 NO_TRACE static inline bool list_empty(const list_t *list) 246 255 { 247 return (list-> head.next == &list->head);256 return (list->__adt_list_head.__adt_link_next == &list->__adt_list_head); 248 257 } 249 258 … … 258 267 static inline link_t *list_first(const list_t *list) 259 268 { 260 return ((list-> head.next == &list->head) ? NULL : list->head.next);269 return ((list->__adt_list_head.__adt_link_next == &list->__adt_list_head) ? NULL : list->__adt_list_head.__adt_link_next); 261 270 } 262 271 … … 271 280 static inline link_t *list_last(const list_t *list) 272 281 { 273 return (list-> head.prev == &list->head) ? NULL : list->head.prev;282 return (list->__adt_list_head.__adt_link_prev == &list->__adt_list_head) ? NULL : list->__adt_list_head.__adt_link_prev; 274 283 } 275 284 … … 283 292 static inline link_t *list_next(const link_t *link, const list_t *list) 284 293 { 285 return (link-> next == &list->head) ? NULL : link->next;294 return (link->__adt_link_next == &list->__adt_list_head) ? NULL : link->__adt_link_next; 286 295 } 287 296 … … 295 304 static inline link_t *list_prev(const link_t *link, const list_t *list) 296 305 { 297 return (link-> prev == &list->head) ? NULL : link->prev;306 return (link->__adt_link_prev == &list->__adt_list_head) ? NULL : link->__adt_link_prev; 298 307 } 299 308 … … 313 322 NO_TRACE static inline void headless_list_split_or_concat(link_t *part1, link_t *part2) 314 323 { 315 part1-> prev->next = part2;316 part2-> prev->next = part1;317 318 link_t *hlp = part1-> prev;319 320 part1-> prev = part2->prev;321 part2-> prev = hlp;324 part1->__adt_link_prev->__adt_link_next = part2; 325 part2->__adt_link_prev->__adt_link_next = part1; 326 327 link_t *hlp = part1->__adt_link_prev; 328 329 part1->__adt_link_prev = part2->__adt_link_prev; 330 part2->__adt_link_prev = hlp; 322 331 } 323 332 … … 364 373 NO_TRACE static inline void list_concat(list_t *list1, list_t *list2) 365 374 { 366 list_splice(list2, list1-> head.prev);375 list_splice(list2, list1->__adt_list_head.__adt_link_prev); 367 376 } 368 377 … … 408 417 static inline bool link_used(link_t *link) 409 418 { 410 if (link-> prev == NULL && link->next == NULL)419 if (link->__adt_link_prev == NULL && link->__adt_link_next == NULL) 411 420 return false; 412 421 413 assert(link-> prev != NULL && link->next != NULL);422 assert(link->__adt_link_prev != NULL && link->__adt_link_next != NULL); 414 423 return true; 415 424 }
Note:
See TracChangeset
for help on using the changeset viewer.