25 #include "dbus-internals.h" 26 #include "dbus-list.h" 27 #include "dbus-mempool.h" 28 #include "dbus-threads-internal.h" 29 #include <dbus/dbus-test-tap.h> 56 alloc_link (
void *data)
63 if (list_pool ==
NULL)
67 if (list_pool ==
NULL)
100 "before we allocated a linked-list link");
124 link->
next = before_this_link;
125 link->
prev = before_this_link->
prev;
126 before_this_link->
prev = link;
129 if (before_this_link == *list)
147 link->
prev = after_this_link;
149 after_this_link->
next = link;
154 #ifdef DBUS_ENABLE_STATS 168 _dbus_mem_pool_get_stats (list_pool, in_use_p, in_free_list_p, allocated_p);
245 return alloc_link (data);
278 *list = (*list)->
next;
298 link = alloc_link (data);
302 link_before (list, *list, link);
322 *list = (*list)->
next;
337 link_before (list, *list, link);
355 if (after_this_link ==
NULL)
359 link = alloc_link (data);
363 link_after (list, after_this_link, link);
381 if (before_this_link ==
NULL)
384 link_before (list, before_this_link, link);
399 if (after_this_link ==
NULL)
402 link_after (list, after_this_link, link);
424 if (link->
data == data)
482 if (link->
data == data)
503 if (link->
next == link)
578 function (link->
data);
613 return (*list)->prev;
629 return (*list)->prev->data;
645 return (*list)->data;
798 (* function) (link->
data, data);
813 return (*list !=
NULL &&
814 (*list)->next == *list);
819 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 820 #include "dbus-test.h" 834 if (link->
next == link)
849 while (link != *list);
860 is_ascending_sequence (
DBusList **list)
884 is_descending_sequence (
DBusList **list)
954 while (link1 && link2)
975 _dbus_list_test (
void)
994 _dbus_test_fatal (
"could not allocate for append");
997 _dbus_test_fatal (
"count not allocate for prepend");
1000 verify_list (&list1);
1001 verify_list (&list2);
1014 verify_list (&list1);
1015 verify_list (&list2);
1023 _dbus_test_fatal (
"could not allocate for append");
1025 _dbus_test_fatal (
"could not allocate for prepend");
1050 verify_list (&list1);
1051 verify_list (&list2);
1068 _dbus_test_fatal (
"could not allocate for append");
1070 _dbus_test_fatal (
"could not allocate for prepend");
1080 void *data1_indirect;
1091 data1_indirect = got_link1->
data;
1095 data2 = link2->
data;
1102 verify_list (&list1);
1103 verify_list (&list2);
1120 _dbus_test_fatal (
"could not allocate for append");
1122 _dbus_test_fatal (
"could not allocate for prepend");
1125 verify_list (&list1);
1126 verify_list (&list2);
1137 while (link2 !=
NULL)
1139 verify_list (&link2);
1149 while (link1 !=
NULL)
1151 verify_list (&link1);
1161 while (link1 !=
NULL)
1163 verify_list (&link1);
1180 _dbus_test_fatal (
"could not allocate for append");
1182 _dbus_test_fatal (
"could not allocate for prepend");
1192 _dbus_test_fatal (
"element should have been in list");
1194 _dbus_test_fatal (
"element should have been in list");
1196 verify_list (&list1);
1197 verify_list (&list2);
1214 _dbus_test_fatal (
"could not allocate for append");
1216 _dbus_test_fatal (
"could not allocate for prepend");
1226 _dbus_test_fatal (
"element should have been in list");
1228 _dbus_test_fatal (
"element should have been in list");
1230 verify_list (&list1);
1231 verify_list (&list2);
1240 while (list1 !=
NULL)
1243 verify_list (&list1);
1245 while (list2 !=
NULL)
1248 verify_list (&list2);
1256 _dbus_test_fatal (
"could not allocate for append");
1258 _dbus_test_fatal (
"could not allocate for prepend");
1264 while (link2 !=
NULL)
1273 verify_list (&list2);
1284 while (link1 !=
NULL)
1293 verify_list (&list1);
1307 _dbus_test_fatal (
"could not allocate for append");
1309 _dbus_test_fatal (
"could not allocate for prepend");
1318 verify_list (&list1);
1319 verify_list (©1);
1323 verify_list (&list2);
1324 verify_list (©2);
1338 verify_list (&list1);
1339 verify_list (©1);
1343 verify_list (&list2);
1344 verify_list (©2);
1353 verify_list (&list1);
1358 verify_list (&list1);
1364 verify_list (&list1);
1370 verify_list (&list1);
1377 _dbus_test_fatal (
"could not allocate for append");
1379 _dbus_test_fatal (
"could not allocate for append");
1381 _dbus_test_fatal (
"could not allocate for append");
1385 verify_list (&list1);
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
void * _dbus_list_get_last(DBusList **list)
Gets the last data in the list.
dbus_bool_t _dbus_list_prepend(DBusList **list, void *data)
Prepends a value to the list.
#define NULL
A null pointer, defined appropriately for C or C++.
void * _dbus_mem_pool_alloc(DBusMemPool *pool)
Allocates an object from the memory pool.
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
void * _dbus_list_pop_last(DBusList **list)
Removes the last value in the list and returns it.
DBusList * next
Next list node.
#define _DBUS_INT_MIN
Minimum value of type "int".
dbus_bool_t _dbus_list_length_is_one(DBusList **list)
Check whether length is exactly one.
DBusList * _dbus_list_get_last_link(DBusList **list)
Gets the last link in the list.
DBusList * _dbus_list_find_last(DBusList **list, void *data)
Finds a value in the list.
dbus_bool_t _dbus_list_insert_after(DBusList **list, DBusList *after_this_link, void *data)
Inserts data into the list after the given existing link.
void _dbus_list_remove_link(DBusList **list, DBusList *link)
Removes a link from the list.
#define _dbus_assert(condition)
Aborts with an error message if the condition is false.
#define _DBUS_INT_TO_POINTER(integer)
Safely stuffs an integer into a pointer, to be extracted later with _DBUS_POINTER_TO_INT.
void _dbus_list_append_link(DBusList **list, DBusList *link)
Appends a link to the list.
void * data
Data stored at this element.
void _dbus_list_insert_before_link(DBusList **list, DBusList *before_this_link, DBusList *link)
Inserts a link into the list before the given existing link.
void _dbus_list_clear_full(DBusList **list, DBusFreeFunction function)
Free every link and every element in the list.
#define _dbus_list_get_prev_link(list, link)
Gets the previous link in the list, or NULL if there are no more links.
DBusList * _dbus_list_alloc_link(void *data)
Allocates a linked list node.
dbus_bool_t _dbus_list_remove(DBusList **list, void *data)
Removes a value from the list.
DBusList * _dbus_list_pop_first_link(DBusList **list)
Removes the first link in the list and returns it.
dbus_bool_t _dbus_mem_pool_dealloc(DBusMemPool *pool, void *element)
Deallocates an object previously created with _dbus_mem_pool_alloc().
DBusList * prev
Previous list node.
void * _dbus_list_get_first(DBusList **list)
Gets the first data in the list.
#define _dbus_list_get_next_link(list, link)
Gets the next link in the list, or NULL if there are no more links.
#define _DBUS_INT_MAX
Maximum value of type "int".
dbus_bool_t _dbus_list_copy(DBusList **list, DBusList **dest)
Copies a list.
void _dbus_list_insert_after_link(DBusList **list, DBusList *after_this_link, DBusList *link)
Inserts a link into the list after the given existing link.
dbus_bool_t _dbus_list_remove_last(DBusList **list, void *data)
Removes a value from the list.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
void _dbus_list_foreach(DBusList **list, DBusForeachFunction function, void *data)
Calls the given function for each element in the list.
void _dbus_mem_pool_free(DBusMemPool *pool)
Frees a memory pool (and all elements allocated from it).
#define _DBUS_POINTER_TO_INT(pointer)
Safely casts a void* to an integer; should only be used on void* that actually contain integers...
void * _dbus_list_pop_first(DBusList **list)
Removes the first value in the list and returns it.
Internals fields of DBusMemPool.
#define _DBUS_UNLOCK(name)
Unlocks a global lock.
#define TRUE
Expands to "1".
#define _dbus_assert_not_reached(explanation)
Aborts with an error message if called.
void _dbus_list_free_link(DBusList *link)
Frees a linked list node allocated with _dbus_list_alloc_link.
void _dbus_list_unlink(DBusList **list, DBusList *link)
Removes the given link from the list, but doesn't free it.
int _dbus_list_get_length(DBusList **list)
Gets the length of a list.
void(* DBusForeachFunction)(void *element, void *data)
Used to iterate over each item in a collection, such as a DBusList.
DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
#define FALSE
Expands to "0".
void _dbus_list_prepend_link(DBusList **list, DBusList *link)
Prepends a link to the list.
#define _DBUS_LOCK(name)
Locks a global lock, initializing it first if necessary.
DBusMemPool * _dbus_mem_pool_new(int element_size, dbus_bool_t zero_elements)
Creates a new memory pool, or returns NULL on failure.
void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.