Commit 9610a1ee 9610a1ee535d364bfc1440f3555e1346e7567178 by Sergey Poznyakoff

(list_remove): Call iterator_advance.

1 parent 7fd44c96
...@@ -23,12 +23,14 @@ ...@@ -23,12 +23,14 @@
23 #include <stdlib.h> 23 #include <stdlib.h>
24 24
25 #include <list0.h> 25 #include <list0.h>
26 #include <iterator0.h>
26 27
27 int 28 int
28 list_create (list_t *plist) 29 list_create (list_t *plist)
29 { 30 {
30 list_t list; 31 list_t list;
31 int status; 32 int status;
33
32 if (plist == NULL) 34 if (plist == NULL)
33 return EINVAL; 35 return EINVAL;
34 list = calloc (sizeof (*list), 1); 36 list = calloc (sizeof (*list), 1);
...@@ -54,6 +56,7 @@ list_destroy (list_t *plist) ...@@ -54,6 +56,7 @@ list_destroy (list_t *plist)
54 list_t list = *plist; 56 list_t list = *plist;
55 struct list_data *current; 57 struct list_data *current;
56 struct list_data *previous; 58 struct list_data *previous;
59
57 monitor_wrlock (list->monitor); 60 monitor_wrlock (list->monitor);
58 for (current = list->head.next; current != &(list->head);) 61 for (current = list->head.next; current != &(list->head);)
59 { 62 {
...@@ -73,6 +76,7 @@ list_append (list_t list, void *item) ...@@ -73,6 +76,7 @@ list_append (list_t list, void *item)
73 { 76 {
74 struct list_data *ldata; 77 struct list_data *ldata;
75 struct list_data *last; 78 struct list_data *last;
79
76 if (list == NULL) 80 if (list == NULL)
77 return EINVAL; 81 return EINVAL;
78 last = list->head.prev; 82 last = list->head.prev;
...@@ -95,6 +99,7 @@ list_prepend (list_t list, void *item) ...@@ -95,6 +99,7 @@ list_prepend (list_t list, void *item)
95 { 99 {
96 struct list_data *ldata; 100 struct list_data *ldata;
97 struct list_data *first; 101 struct list_data *first;
102
98 if (list == NULL) 103 if (list == NULL)
99 return EINVAL; 104 return EINVAL;
100 first = list->head.next; 105 first = list->head.next;
...@@ -116,6 +121,7 @@ int ...@@ -116,6 +121,7 @@ int
116 list_is_empty (list_t list) 121 list_is_empty (list_t list)
117 { 122 {
118 size_t n = 0; 123 size_t n = 0;
124
119 list_count (list, &n); 125 list_count (list, &n);
120 return (n == 0); 126 return (n == 0);
121 } 127 }
...@@ -133,6 +139,7 @@ list_comparator_t ...@@ -133,6 +139,7 @@ list_comparator_t
133 list_set_comparator (list_t list, list_comparator_t comp) 139 list_set_comparator (list_t list, list_comparator_t comp)
134 { 140 {
135 list_comparator_t old_comp; 141 list_comparator_t old_comp;
142
136 if (list == NULL) 143 if (list == NULL)
137 return NULL; 144 return NULL;
138 old_comp = list->comp; 145 old_comp = list->comp;
...@@ -152,6 +159,7 @@ list_remove (list_t list, void *item) ...@@ -152,6 +159,7 @@ list_remove (list_t list, void *item)
152 struct list_data *current, *previous; 159 struct list_data *current, *previous;
153 list_comparator_t comp; 160 list_comparator_t comp;
154 int status = ENOENT; 161 int status = ENOENT;
162
155 if (list == NULL) 163 if (list == NULL)
156 return EINVAL; 164 return EINVAL;
157 comp = list->comp ? list->comp : def_comp; 165 comp = list->comp ? list->comp : def_comp;
...@@ -161,6 +169,7 @@ list_remove (list_t list, void *item) ...@@ -161,6 +169,7 @@ list_remove (list_t list, void *item)
161 { 169 {
162 if (comp (current->item, item) == 0) 170 if (comp (current->item, item) == 0)
163 { 171 {
172 iterator_advance (list->itr, current);
164 previous->next = current->next; 173 previous->next = current->next;
165 current->next->prev = previous; 174 current->next->prev = previous;
166 free (current); 175 free (current);
...@@ -198,15 +207,13 @@ list_replace (list_t list, void *old_item, void *new_item) ...@@ -198,15 +207,13 @@ list_replace (list_t list, void *old_item, void *new_item)
198 return status; 207 return status;
199 } 208 }
200 209
201 /* FIXME: FIXME: FIXME: URGENT:
202 Every time we iterate through the loop to get the data, an easy
203 fix is to a an index to the current. */
204 int 210 int
205 list_get (list_t list, size_t indx, void **pitem) 211 list_get (list_t list, size_t indx, void **pitem)
206 { 212 {
207 struct list_data *current; 213 struct list_data *current;
208 size_t count; 214 size_t count;
209 int status = ENOENT; 215 int status = ENOENT;
216
210 if (list == NULL || pitem == NULL) 217 if (list == NULL || pitem == NULL)
211 return EINVAL; 218 return EINVAL;
212 monitor_rdlock (list->monitor); 219 monitor_rdlock (list->monitor);
...@@ -229,6 +236,7 @@ list_do (list_t list, list_action_t * action, void *cbdata) ...@@ -229,6 +236,7 @@ list_do (list_t list, list_action_t * action, void *cbdata)
229 { 236 {
230 struct list_data *current; 237 struct list_data *current;
231 int status = 0; 238 int status = 0;
239
232 if (list == NULL || action == NULL) 240 if (list == NULL || action == NULL)
233 return EINVAL; 241 return EINVAL;
234 monitor_rdlock (list->monitor); 242 monitor_rdlock (list->monitor);
......