2 * This file is part of buxton.
4 * Copyright (C) 2014 Intel Corporation
6 * buxton is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
23 #define _cleanup_list_ __attribute__ ((cleanup(buxton_list_free)))
24 #define _cleanup_list_all_ __attribute__ ((cleanup(buxton_list_free_all)))
27 * A singly-linked list
29 typedef struct BuxtonList {
30 void *data; /**<Data for this item in the list */
31 struct BuxtonList *next; /**<Next item in the list */
32 struct BuxtonList *tail; /**<Tail of the list */
33 uint64_t size; /**<Size of list */
36 #define BUXTON_LIST_FOREACH(list, elem) \
37 for ((elem) = (list); (elem) != NULL; (elem)=(elem)->next)
41 * Append data to an existing list, or create a new list if NULL
43 * @note May return false if memory allocation errors exist
44 * @param list Pointer to BuxtonList pointer
45 * @param data Data pointer to store in the list
46 * @return a boolean value, indicating success of the operation
48 bool buxton_list_append(BuxtonList **list, void *data);
51 * Prepend data to an existing list, or create a new list if NULL
52 * Much faster than append
54 * @note May return false if memory allocation errors exist
55 * @param list Pointer to BuxtonList pointer
56 * @param data Data pointer to store in the list
57 * @return a boolean value, indicating success of the operation
59 bool buxton_list_prepend(BuxtonList **list, void *data);
62 * Remove the given element from the list
64 * @param list Pointer to a BuxtonList pointer
65 * @param data Remove item with the matching data pointer
66 * @param do_free Whether to free the item
67 * @return a boolean value, indicating success of the operation
69 bool buxton_list_remove(BuxtonList **list, void *data, bool do_free);
72 * Free all items in the list
74 static inline void buxton_list_free(void *p)
76 BuxtonList *list = *(BuxtonList**)p;
80 BuxtonList *elem, *node = NULL;
82 while (elem != NULL) {
90 * Free all items in the list and their items
92 static inline void buxton_list_free_all(void *p)
94 BuxtonList *list = *(BuxtonList**)p;
98 BuxtonList *elem, *node = NULL;
100 while (elem != NULL) {
109 * Editor modelines - http://www.wireshark.org/tools/modelines.html
114 * indent-tabs-mode: t
117 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
118 * :indentSize=8:tabSize=8:noTabs=false: