25 #include "dbus-internals.h"
26 #include "dbus-list.h"
27 #include "dbus-mempool.h"
28 #include "dbus-threads-internal.h"
55 alloc_link (
void *data)
61 if (list_pool ==
NULL)
65 if (list_pool ==
NULL)
119 link->
next = before_this_link;
120 link->
prev = before_this_link->
prev;
121 before_this_link->
prev = link;
124 if (before_this_link == *list)
142 link->
prev = after_this_link;
144 after_this_link->
next = link;
149 #ifdef DBUS_ENABLE_STATS
156 _dbus_mem_pool_get_stats (list_pool, in_use_p, in_free_list_p, allocated_p);
233 return alloc_link (data);
266 *list = (*list)->
next;
286 link = alloc_link (data);
290 link_before (list, *list, link);
310 *list = (*list)->
next;
325 link_before (list, *list, link);
343 if (after_this_link ==
NULL)
347 link = alloc_link (data);
351 link_after (list, after_this_link, link);
369 if (before_this_link ==
NULL)
372 link_before (list, before_this_link, link);
387 if (after_this_link ==
NULL)
390 link_after (list, after_this_link, link);
412 if (link->
data == data)
470 if (link->
data == data)
491 if (link->
next == link)
574 return (*list)->prev;
590 return (*list)->prev->data;
606 return (*list)->data;
759 (* function) (link->
data, data);
774 return (*list !=
NULL &&
775 (*list)->next == *list);
780 #ifdef DBUS_BUILD_TESTS
781 #include "dbus-test.h"
795 if (link->
next == link)
810 while (link != *list);
821 is_ascending_sequence (
DBusList **list)
845 is_descending_sequence (
DBusList **list)
915 while (link1 && link2)
936 _dbus_list_test (
void)
961 verify_list (&list1);
962 verify_list (&list2);
975 verify_list (&list1);
976 verify_list (&list2);
1009 verify_list (&list1);
1010 verify_list (&list2);
1039 void *data1_indirect;
1050 data1_indirect = got_link1->
data;
1054 data2 = link2->
data;
1061 verify_list (&list1);
1062 verify_list (&list2);
1082 verify_list (&list1);
1083 verify_list (&list2);
1094 while (link2 !=
NULL)
1096 verify_list (&link2);
1106 while (link1 !=
NULL)
1108 verify_list (&link1);
1118 while (link1 !=
NULL)
1120 verify_list (&link1);
1151 verify_list (&list1);
1152 verify_list (&list2);
1183 verify_list (&list1);
1184 verify_list (&list2);
1193 while (list1 !=
NULL)
1196 verify_list (&list1);
1198 while (list2 !=
NULL)
1201 verify_list (&list2);
1215 while (link2 !=
NULL)
1224 verify_list (&list2);
1235 while (link1 !=
NULL)
1244 verify_list (&list1);
1267 verify_list (&list1);
1268 verify_list (©1);
1272 verify_list (&list2);
1273 verify_list (©2);
1287 verify_list (&list1);
1288 verify_list (©1);
1292 verify_list (&list2);
1293 verify_list (©2);
1302 verify_list (&list1);
1307 verify_list (&list1);
1313 verify_list (&list1);
1319 verify_list (&list1);
1331 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 * _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.
#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.
#define _DBUS_DEFINE_GLOBAL_LOCK(name)
Defines a global lock variable with the given name.
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.
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.